Hello @bostjanlaba
First, if you have hidden fields by dependencies, the values of the inactive fields are zero in the equations.
If you want to reset the form by selecting a dropdown field, for example, it is the fieldname1 (you should use the name of the field in your form). Insert an “HTML Content” field in the form with the following piece of code as its content:
<script>
jQuery(document).on('change', '[id*="fieldname1_"]', function(){
var f = jQuery(this), v = f.val();
this.form.reset();
f.val(v).change();
});
</script>
Best regards.
Hi,
the code does reset everything but not to default calculated values (as reset button does) but to null values. So all calculated fields become empty…
Hello @bostjanlaba
If you want to evaluate all the equations after reset the form, you can edit the piece of code as follows:
<script>
jQuery(document).on('change', '[id*="fieldname1_"]', function(){
var f = jQuery(this), v = f.val();
this.form.reset();
f.val(v);
EVALEQUATIONS(this.form);
});
</script>
Best regards.
Wow, amazing!
Thank you, your support is the best!
Bostjan
I was just a bit too quick on the result. How do I exclude first field from resetting? Because now I change the field and it resets everything properly along with the first field (“fieldname1_”) itself which is not correct.
Thank you.
Hello @bostjanlaba
In the piece of code I sent you previously, you should replace fieldname1 with the name of the field in your form.
Best regards.
Yes, of course, I understood that from first message 🙂
However, reset still influences all the fields, including this first field.
Hello @bostjanlaba
Please, send me the link to your form to check it in action.
Best regards.
https://tehnicni.info/?cff-form=7
Start changing selection in first field and you will notice, the field won’t “stay” on your selection but rather reset itself also.
Hello @bostjanlaba
The code is working fine, but as there are several options with the same value, the code I sent you will select the first of them with the field’s value. To use the option index instead of its value, please, edit the code as follows:
<script>
jQuery(document).on('change', '[id*="fieldname3_"]', function(){
var i = this.selectedIndex;
this.form.reset();
this.selectedIndex = i;
EVALEQUATIONS(this.form);
});
</script>
Best regards.
Works, thank you.
Just as a side question, is it somehow possible to use field value’s substring for conditionals?
Like my dropdown has:
Car|1
Truck|2
Ship|3
I use 2nd column for calcuations (1,2,3 in this example), which works. But sometimes I need to do (example):
IF fieldname3_1.column1 has value “Ca” in the string THEN…
Of course inside the plugin I still leave values from column2 to be used for calculations.
Is it possible to create such query?
Thanks
Bostjan
Hello @bostjanlaba
If you have entered the choices values of the fieldname1 field with the format: text|number you can implement the equation as follows:
(function(){
var t = fieldname1.split('|')[0],
n = fieldname1.split('|')[1]*1;
/* Now your code to use the text t and/or the number n */
})()
Best regards.