• Resolved bostjanlaba

    (@bostjanlaba)


    I have many fields and conditionals set. First field is a dropdown and based on the user selection in this field, some fields get shown, some hidden etc.

    I would need to somehow reset all fields to default when user changes a selection in the first field. I know I can put a reset button but by the looks of it, users are unaware that if they did some calculation based already in this form and then change the 1st field, the “old” values remain saved and are used in the calculation, even though some fields get hidden.

    Any way to do that?

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    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…

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    Wow, amazing!

    Thank you, your support is the best!

    Bostjan

    Thread Starter bostjanlaba

    (@bostjanlaba)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    Yes, of course, I understood that from first message 🙂

    However, reset still influences all the fields, including this first field.

    Plugin Author codepeople

    (@codepeople)

    Hello @bostjanlaba

    Please, send me the link to your form to check it in action.

    Best regards.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    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

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter bostjanlaba

    (@bostjanlaba)

    Thank you. Perfect.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Resetting the form by dropdown change’ is closed to new replies.