Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

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

Open
iSynth opened this issue Apr 7, 2016 · 4 comments
Open

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

iSynth opened this issue Apr 7, 2016 · 4 comments

Comments

@iSynth
Copy link

iSynth commented Apr 7, 2016

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

@re8us
Copy link

re8us commented Jul 28, 2016

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
Copy link
Member

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

@re8us
Copy link

re8us commented Sep 10, 2016

@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
Copy link
Member

tonydspaniard commented Jul 5, 2017

Thanks! checking

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants