开发者

Django - jQuery - change() function on DateField()

开发者 https://www.devze.com 2023-01-26 17:32 出处:网络
I have 2 date fields (from_date, to_date) in django admin site for a model.Whenever the value of \'from_date\' changed, I need to add from开发者_高级运维_date + 10 more days to the to_date field. I ha

I have 2 date fields (from_date, to_date) in django admin site for a model. Whenever the value of 'from_date' changed, I need to add from开发者_高级运维_date + 10 more days to the to_date field. I have used change() event of the from_date text box. The problem is that When I choose the date from Date Widget, this change() is not getting called. Any suggestions to deduct this change?


The reason the change event is not fired is because the value is changed programmatically instead of by the user, after which the input field recieves focus. Upon losing focus, the input field detects no changes, as the value is not changed during the time the widget was focussed.

I would suggest using the onBlur() event listener of the TextInput to change the to_date field, which is fired as soon as a input widget loses focus:

$('.dateinput').blur(function() {
    // Calculate to_date here
})
0

精彩评论

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

关注公众号