Hide and Show fields
-
Hi, I want to know how to hide or show one field that is dependent on other two fields? The other two fields have dropdowns. So, I want that if I select sepcific options from these two other fields, it would hide or show that third field
-
Anyone here?
Hello @asjad492
You made the same question in your other support thread:
https://www.ads-software.com/support/topic/applying-dependency-for-calculated-fied/
Best regards.
You didnt understand my question. I’m saying that the field is dependent on other two fields. Now issue is one of those fields is there all the time and second one is used everytime. So I want that that one field should only show when I use options from both fields
Hello @asjad492
As I described in your other support thread, if a field is dependent on complex rules, like multiple fields’ values, you must configure the dependency via an equation in an auxiliary calculated field instead of the other fields.
For example, assuming you have the fieldname1. It must be only enabled if the fieldname2 value is 3, and the fieldname3 value is 10.
The equation in this hypothetical example would be:
(function(){ IGNOREFIELD(fieldname1|n); if(AND(fieldname2 == 3, fieldname3 == 10)){ ACTIVATEFIELD(fieldname1|n); } })()
If you want to activate the fieldanem1 if the value of the fieldname2 field is 3 or the value of the fieldname3 field is 10, the equation would use an “or”.
(function(){ IGNOREFIELD(fieldname1|n); if(OR(fieldname2 == 3, fieldname3 == 10)){ ACTIVATEFIELD(fieldname1|n); } })()
The conditions can be as simple or complex as your project needs.
Best regards.
Hi, Will fieldname1 remain hidden from the form if condition is not met?
I just checked, other fields are still showing
Hi, so it worked. Now the issue is I have to press calculate button to work it. I have turned off calculate dynamically option in form settings as I want other fields to only calculate when I press button. Is there any way that this field executes function right away without pressing calculate button?
Hello @asjad492
If you disabled the dynamic evaluation of the equation, it is possible to evaluate that specific equation by coding.
Continuing with the previous example.
Assuming the calculated field is the fieldname4, you can insert an “HTML Content” field in the form with the following code as its content:
<script> jQuery(document).on('change', '[id*="fieldname2_"],[id*="fieldname3_"]', function(){ EVALEQUATION('fieldname4'); }); </script>
Best regards.
I don’t have to specify values of fieldname2 and fieldname3 here in HTML?
Hello @asjad492
If you prefer, you can implement the complete process in the HTML Content field:
<script> jQuery(document).on('change', '[id*="fieldname2_"],[id*="fieldname3_"]', function(){ IGNOREFIELD('fieldname1'); if(AND(getField('fieldname2').val() == 3, getField('fieldname3').val() == 10)){ ACTIVATEFIELD('fieldname1'); } }); </script>
Best regards.
I have multiple fields to activate. So, I will write in same HTML field for all fields?
(function(){ IGNOREFIELD(fieldname14|n); IGNOREFIELD(fieldname42|n); IGNOREFIELD(fieldname43|n); IGNOREFIELD(fieldname44|n); if(AND(fieldname40 == 'Basis-Shop', fieldname16 == 'Normales Angebot (Jetzt kaufen)')){ ACTIVATEFIELD(fieldname14|n); } else if(AND(fieldname40 == 'Top-Shop', fieldname16 == 'Normales Angebot (Jetzt kaufen)')){ ACTIVATEFIELD(fieldname42|n); } else if(AND(fieldname40 == 'Basis-Shop', fieldname16 == 'Auktionsangebot')){ ACTIVATEFIELD(fieldname44|n); } else if(AND(fieldname40 == 'Top-Shop', fieldname16 == 'Auktionsangebot')){ ACTIVATEFIELD(fieldname45|n); } })()
Hello @asjad492
Do not confuse the equations with the HTML Content fields. In the HTML Content fields you access the fields’ values by calling the getField operation, like
getField('fieldname40').val() == 'Top-Shop'
and to ignore or activate fieldIGNOREFIELD('fieldname14');
You can access the fields values directly by the fields’ names, or using the modifiers like
|n
only in the equations context.Best regards.
If I use entire code in HTML as you suggested like this one:
<script> jQuery(document).on('change', '[id*="fieldname2_"],[id*="fieldname3_"]', function(){ IGNOREFIELD('fieldname1'); if(AND(getField('fieldname2').val() == 3, getField('fieldname3').val() == 10)){ ACTIVATEFIELD('fieldname1'); } }); </script>
I don’t have to press calculate button to proceed it?
Exactly !!!!
This isn’t working.
<script> jQuery(document).on('change', '[id*="fieldname40_"],[id*="fieldname16_"]', function(){ IGNOREFIELD('fieldname14'); IGNOREFIELD('fieldname42'); IGNOREFIELD('fieldname43'); IGNOREFIELD('fieldname44'); if(AND(getField('fieldname40').val() == 'Basis-Shop', getField('fieldname16').val() == 'Normales Angebot (Jetzt kaufen)')) { ACTIVATEFIELD('fieldname14'); } else if(AND(getField('fieldname40').val() == 'Top-Shop', getField('fieldname16').val() == 'Normales Angebot (Jetzt kaufen)')) { ACTIVATEFIELD('fieldname42'); } else if(AND(getField('fieldname40').val() == 'Top-Shop', getField('fieldname16').val() == 'Auktionsangebot')) { ACTIVATEFIELD('fieldname42'); } else if(AND(getField('fieldname40').val() == 'Basis-Shop', getField('fieldname16').val() == 'Auktionsangebot')) { ACTIVATEFIELD('fieldname42'); } }); </script>
- The topic ‘Hide and Show fields’ is closed to new replies.