Restrict selecting future date in child table field

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

anyone??


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())
            });
        }
    });
});

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:

1 Like

yes, :smile: :grin:

1 Like

Thanks for sharing your own-learning process! This kind of tricks are really useful
:wink::slight_smile:

2 Likes