Page 1 of 1

How to clear fields from javascript in EDIT page (in Client side events)

Posted: Wed Jun 15, 2022 11:26 pm
by Andros

In my table I have a "AllCustomers" flag field (1=select all customers, 0=select specific customers) and a "SpecificCustomersList" multiple select list (varchar linked to a lookup table)
In the "Client side events" of the AllCustomers field, if the user set "AllCustomers"=0 I want also to clear the SpecificCustomersList field, but the following code doesn't work: the field is set visible or not in the right way, but the list is not cleared. How to do this?
{ // keys = event types, values = handler functions
"change": function(e) {
if ($(this).val() === "1") {
$(this).fields("SpecificCustomersList").visible(true); // this works
} else {
$(this).fields("SpecificCustomersList").visible(false); // this works
$(this).fields("SpecificCustomersList").val(''); // this doesn't work, also tried value('') and value(null)
}
}
}

I have also other similar scenarios where I need to clear a multiple file upload field. How to clear it in the Client side events?


Re: How to clear fields from javascript in EDIT page (in Client side events)

Posted: Thu Jun 16, 2022 8:26 am
by MichaelG

For select2 fields, you need to trigger the change event of the select2. For example:

                $(this).fields("Select2").val('');
                $("#x_Select2").select2().trigger("change");

For file upload field, you need to clear the file related attributes as follows:

                $("#fn_x_Fileupload").val('');
                $("#fa_x_Fileupload").val('0');
                $("#ft_x_Fileupload").find("tr").remove();

Re: How to clear fields from javascript in EDIT page (in Client side events)

Posted: Fri Jun 17, 2022 2:11 am
by Andros

Perfect!
How to disable a checkbox?
$(this).fields("IsActive").disabled(true); //doesn't work


Re: How to clear fields from javascript in EDIT page (in Client side events)

Posted: Fri Jun 17, 2022 7:46 am
by MichaelG

$("#x_Checkbox").prop("disabled", true);