Home › Forums › Classic DFFS › Clearing the values of fiellds on form save
- This topic has 3 replies, 2 voices, and was last updated 4 years, 9 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 24, 2020 at 15:51 #28814
I have a complex multiple sections requirement where each section and fields under those are visible/hidden based on change of other dropdowns
So I had to use custom JS.
I have used rules just to trigger change of dropdowns
onload I use this to hide all the fields and conditionally start showing them by doing this:
$(spjs.dffs.fields[“Products”]).hide();Sometimes user might fill out a value or select dropdown value but then choose to select some other value which will hide this field.
At the end on before save, I would like to clear any such values that were selected by user but are now hidden.
$(“td[style$=’display: none;’]”).closest(‘tr’).find(“select”).each(function(i) {
alert($(this).prop(‘title’));
$(this).prop(‘selectedIndex’,’-1′);});
This is clearing all selects not just the one with style$=’display: none;’
Is there an easier way to clear all the fields that are not visible in a tab -
February 24, 2020 at 19:17 #28832
I guess this is the same question as this one – so the answer is the same:
var arrOfHidden = ["FieldOne", "FieldTwo"]; jQuery.each(arrOfHidden, function(i, fin){ setFieldValue(fin, ""); });
Alexander
-
February 25, 2020 at 02:04 #28841
Thank you. But I have some 70 fields that are conditionally shown and hidden.
So I was trying to find some option to identify all those hidden elements at once, instead of building an array, on PreSaveAction
The below code does the trick to reset the select dropdowns . But I was wondering if there is a better way or inbuilt option?function PreSaveAction() { $("td[<strong>style$='display: none;</strong>']").closest('td').find("input").each(function(j) { $(this).attr('value',''); }); $("td[style$='display: none;']").closest('td').find("select").each(function(i) { $(this).prop('selectedIndex','-1'); }); }
Is there an easy way to set fields to Not required when the fields are hidden in a dffs form? I am using flag_Mandatory and clear_Mandatory to conditionally make fields required and vice versa but it’s becoming very messy when I have multiple functions being called amking some fields to show and others to hide.
-
February 25, 2020 at 16:31 #28865
In general I would recommend that you used rules to control showing and hiding fields – is there a specific reason you use custom js and not rules?
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.