This topic contains 3 replies, has 2 voices, and was last updated by Sean Sean 3 years ago.

jquery set datepicker value german date


  • olihand
    Participant

    Posts: 3
    Member Reply #1315

    hi there,

    i´m using the datepicker with german dates. when i set the value per php with this code, everything works as intended:

    <div class=”col-md-3″>
    <div class=”form-group”>
    <label class=”control-label”>Datum <span class=”required”>*</span></label>
    <div data-date-format=”dd.mm.yyyy” class=”input-group date date-picker”>
    <input type=”text” id=”unitsEditDialog_date” name=”unitsEditDialog_date” value=”<?=date(“d.m.Y”)?>” class=”form-control” aria-required=”true” aria-invalid=”false” aria-describedby=”datepicker-error” placeholder=”TT.MM.JJJJ”>
    <span class=”input-group-btn”>
    <button type=”button” class=”btn default”><i class=”fa fa-calendar”></i></button>
    </span>
    </div>
    </div>
    </div>

    in jquery i use the following code to initialize the datepickers:

    $(‘.date-picker’).datepicker({
    rtl: Metronic.isRTL(),
    language: “de-DE”,
    clearBtn: true,
    autoclose: true
    });

    my problem:

    i have another datepicker element in a modal dialog, which is set up totally equally but get´s set dynamically only. this means, i can´t set a value per php (value=””) but only with jquery / javascript when i acutally display the modal:

    $(‘#unitsEditDialog_date’).val(‘15.02.2015’).datepicker(‘update’, ‘15.02.2015’);

    but here i get some strange errors. the date element and the right button seem to be out of sync, i.e. they both display different dates after i set a value. it seems, the button component does not get updated, no matter what i try (variations):

    $(‘#unitsEditDialog_date’).val(‘15.02.2015’);
    $(‘#unitsEditDialog_date’).datepicker(‘update’, ‘15.02.2015’);

    can you please help me, and point out what i´m doing wrong or how i could notify the button of the datepicker to update after change?

    thx a lot 🙂

     

    Sean
    Sean
    Keymaster

    Posts: 4470
    Support Staff Reply #1348

    Hi :),

    You can pass value from PHP to JS using JS variables:

    var jsvalue = ‘<?php echo $value?>’;

    And use that variable anywhere you need(on modal call, etc).

    Thanks.


    olihand
    Participant

    Posts: 3
    Member Reply #1364

    hi there,

    thanx for your answer, but that doesn´t help me at this point. i have no default value, which i could set at page load, i need to set the values dynamically on the fly with javascript / jquery. how do you set the correct value for german dates?

    $(‘#unitsEditDialog_date’).val(‘15.02.2015′);

    does not work, either does

    $(‘#unitsEditDialog_date’).datepicker(‘update’, ‘15.02.2015’);

    thx a lot!

    • This reply was modified 3 years ago by  olihand.
    Sean
    Sean
    Keymaster

    Posts: 4470
    Support Staff Reply #1385

    Hi,

    To change the default date format you can use ‘format’ parameter of the plugin:

    http://bootstrap-datepicker.readthedocs.org/en/latest/options.html#format

    To use i18n you can follow http://bootstrap-datepicker.readthedocs.org/en/latest/i18n.html

    But we are unable to support your application/project level logics/requirements(loading dates dynamicaly, etc) since the theme implementation after purchase is responsibility of buyers.

    Thanks.

     

You must be logged in to reply to this topic.