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

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
Andros
User
Posts: 111

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

Post 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?


MichaelG
User
Posts: 1095

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

Andros
User
Posts: 111

Post by Andros »

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


MichaelG
User
Posts: 1095

Post by MichaelG »

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


Post Reply