• Resolved eliag88

    (@eliag88)


    Hello! I’ve just started using the pro version of this plugin, and I’m needing to skip a step when a certain value is present in a field within the form. I’ve been able to retrieve the field’s value, but have had no luck skipping a step with the example in https://conditional-fields-cf7.bdwm.be/multistep-example-move-to-specific-step-programatically/

    I keep getting Uncaught ReferenceError: wpcf7cf is not defined. I tried to amend the snippet to this, I’m sure I’m missing something obvious, but I’ve been trying for hours to no avail. I really need to work this out as it will force us to change plugins if we can’t skip steps 🙁

    Note: I can’t link the page as it’s not allowed to go live on the site yet.

    <script>        
    	(function($){
          $form = $('.wpcf7-form');
              
    		var powertypevar = document.getElementById('power-type-pre').value;
            
    		if (powertypevar != 'ABB7kW') {
            wpcf7cf.multistepMoveToStep($form, 3);
                return false;
          }
      })(jQuery)
    
    </script>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jules Colle

    (@jules-colle)

    You are probably calling this script before the WPCF7CF scripts are loaded.

    The first thing I would recommend you to try is to add the code snippet in your actual form code at the bottom. Note that you need to Remove alle blank lines from the code if you do this, otherwise CF7 will convert these to paragraphs resulting in an invalid script.

    Feel free to use the form tester to fiddle around with your code: https://conditional-fields-cf7.bdwm.be/form-tester/?test-form=blank+form

    Thread Starter eliag88

    (@eliag88)

    Hello! Thank you so much for the response!

    You’re right, it was firing before the scripts loaded. Even when the form was in the footer, because there was no interaction it was firing too soon. I’m not too familiar with jQuery to manipulate this adequately. The problem is how to fire this only when the user is in a certain step and to avoid continuing ad eternum.

    It would be a fantastic addition in the future if you could add a visual way to work this!

    So I can fire this on demand once the user clicks “next” based on a field’s value. Can you help me read what step the user is in at the moment, so I can fire only from that step’s number?

    http://conditional-fields-cf7.bdwm.be/form-tester/?hash=d48e500314de81987e2c2bb9c0690c28

    My call:

    <script>
      (function($){
          $form = $('.wpcf7-form');
          $form.click(function(e){
              const $clickedElement = $(e.target);
              var ozevselection = document.getElementById('ozev-select').value;
    	if (ozevselection == 'No') {
    // Can I use any parameter here to know what step the user is on and include it in this if?
              if ($clickedElement.hasClass('wpcf7cf_next')) {
                  wpcf7cf.multistepMoveToStep($form, 4);
                  return false;
              }
              }
          });
      })(jQuery)
    </script>

    Thanks again!

    Plugin Author Jules Colle

    (@jules-colle)

    var currentStep = wpcf7cf.getMultiStepObj(jQuery('.wpcf7-form').eq(0)).currentStep

    Of course, if you already have a reference to the jquery form object, you can do:

    wpcf7cf.getMultiStepObj($form).currentStep

    Plugin Author Jules Colle

    (@jules-colle)

    Just to be complete, this should also work:

    wpcf7cf.getMultiStepObj('.wpcf7-form').currentStep
    
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Skip step via validating field value’ is closed to new replies.