开发者

Jquery UI datepicker plugin - How to change alt field?

开发者 https://www.devze.com 2023-02-04 22:27 出处:网络
I have an issue where a user changes a date directly in the input field the alt field does not update. The only time the alt field updates is when the calendar is used to select a specific day.

I have an issue where a user changes a date directly in the input field the alt field does not update. The only time the alt field updates is when the calendar is used to select a specific day.

Code example:

$this
.find('#'+strInputID)
.dat开发者_高级运维epicker({altField: '#alt_'+strInputID, altFormat: 'dd/mm/yy', minDate: new Date()})
.datepicker("setDate" , dDfltDate);

Please note that I am using altFormat because the input field changes depending on localisation, so I can't copy the value across directly whenever the input has changed.

Does Jquery Datepicker have anything to allow for this?

The events list here does not have what I want: http://jqueryui.com/demos/datepicker/

Does anyone have any answers to how this could be fixed?

EDIT: This example http://jqueryui.com/demos/datepicker/#alt-field works, I found another example that didn't. As we are using v1.7.3 and not 1.8.8 I can assume that this might be the problem.

I can not upgrade so I will continue to test and see if this is definately the case. If anyone knows otherwise then please let me know. Thanks


I managed to get it working by bolting on 1.8.8 datepicker code on to the keyup event of the input field, but this isn't an elegant approach :( Any other suggestions are welcome. Thanks

var inputField = $this.find('#'+strInputID);
inputField.datepicker({altField: '#alt_'+strInputID, altFormat: 'dd/mm/yy', minDate: new Date()}).datepicker("setDate", dDfltDate);
inputField.keyup(function (event) {
    var inst = $.datepicker._getInst(event.target);
    if (inst.input.val() != inst.lastVal) {
        try {
            var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
                (inst.input ? inst.input.val() : null),
                $.datepicker._getFormatConfig(inst));
            if (date) { // only if valid
                $.datepicker._setDateFromField(inst);
                $.datepicker._updateAlternate(inst);
                $.datepicker._updateDatepicker(inst);
            }
        }
        catch (event) {
            $.datepicker.log(event);
        }
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号