ejaaz
1
My child table contains a date field. I want to prevent users from selecting a future date in this field by disabling future dates in the datepicker.
Here is what I have tried…
cur_frm.fields_dict.field_name.grid.frm.fields_dict.bill_date.datepicker.update({
maxDate: new Date(frappe.datetime.get_today())
});
cur_frm.fields_dict.field_name.grid.debounced_refresh();
1 Like
ejaaz
3
I manage to do this in a child table when the child table popup is not open, but this code is not working when the popup is open.
my code
$('div[data-fieldname="bill_date"]').click(function(){
cur_frm.fields_dict.field_name.grid.grid_rows.forEach(element => {
if (Object.keys(element.on_grid_fields_dict).length){
element.on_grid_fields_dict.bill_date.datepicker.update({
maxDate: new Date(frappe.datetime.get_today())
});
}
});
});
ejaaz
4
Continuing from my previous reply…
I manage to do this by this code when child table popup is open
form_render: (frm, cdt, cdn) => {
$('input[data-fieldname="bill_date"]').click(function(){
frm.cur_grid.grid_form.fields_dict.bill_date.datepicker.update({
maxDate: new Date(frappe.datetime.get_today())
});
});
},
2 Likes
Don’t forget to add a validation on the server side of things ![:smile: :smile:](https://discuss.frappe.io/images/emoji/twitter/smile.png?v=12)
1 Like
avc
7
Thanks for sharing your own-learning process! This kind of tricks are really useful
![:wink: :wink:](https://discuss.frappe.io/images/emoji/twitter/wink.png?v=12)
![:slight_smile: :slight_smile:](https://discuss.frappe.io/images/emoji/twitter/slight_smile.png?v=12)
2 Likes