2amigos / yii2-date-picker-widget

Bootstrap DatePicker Widget for Yii2
https://2amigos.us
Other
130 stars 77 forks source link

How to use other options and methods from original JavaScript? #24

Open iSynth opened 8 years ago

iSynth commented 8 years ago

How to use this - http://bootstrap-datepicker.readthedocs.org/en/v1.6.0/options.html#format ?

re8us commented 8 years ago

It seems may be like this

<?= $form->field($model, 'done_till')->widget(DatePicker::className(), 
    [
        'inline' => true,
        'template' => '<div class="well" style="background-color: #fff; width:250px">{input}</div>', 
        'language' => 'ru',
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => new JsExpression('{
                toDisplay: function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() - 7);
                    return d.toISOString();
                },
                toValue: function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() + 7);
                    return new Date(d);
                }
            }'),
        ]
    ]
);?>

or like this

<?= $form->field($model, 'done_till')->widget(DatePicker::className(), 
    [
        'inline' => true,
        'template' => '<div class="well" style="background-color: #fff; width:250px">{input}</div>', 
        'language' => 'ru',
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => [
                'toDisplay' => new JsExpression('function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() - 7);
                    return d.toISOString();
                }'),
                'toValue' => new JsExpression('function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() + 7);
                    return new Date(d);
                }')
            ]
        ]
    ]
);?>

But it doesn't work. Any ideas?

tonydspaniard commented 8 years ago

@re8us what is the response on your browser? can we have a look at the javascript code rendered?

re8us commented 8 years ago

@tonydspaniard sure

jQuery(document).ready(function () {
;jQuery('#task-deadline').parent().datepicker({"autoclose":true,"format":"dd.mm.yyyy","class":"col-md-3","language":"ru"});
;jQuery('#task-done_till').parent().datepicker({"autoclose":true,"format":{
                toDisplay: function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() - 7);
                    return d.toISOString();
                },
                toValue: function (date, format, language) {
                    var d = new Date(date);
                    d.setDate(d.getDate() + 7);
                    return new Date(d);
                }
            },"language":"ru"});
;jQuery('#task-done_till').parent().on('changeDate', function (e){ jQuery('#task-done_till').val(e.format());});
jQuery('#w0').yiiActiveForm([{"id":"task-sum","name":"sum","container":".field-task-sum","input":"#task-sum","error":".help-block.help-block-error","validate":function (attribute, value, messages, deferred, $form) {yii.validation.number(value, messages, {"pattern":/^\s*[+-]?\d+\s*$/,"message":"Значение «Сумма» должно быть целым числом.","skipOnEmpty":1});}}], []);
});

and error 2016-09-10 20 46 02

tonydspaniard commented 7 years ago

Thanks! checking