• Resolved niklaskristiansson

    (@niklaskristiansson)


    Hi,

    I have a button that I try to program for: OnClick check for all required fields filled. If they are: reveal a hidden field, else: the default highlight field with the error message “required field data missing.”

    I tried this formula in the OnClick event for the button, but can’t get it working:
    if(jQuery(this.form).valid()) jQuery(‘.kontaktuppgifter *’).removeClass(‘hide’);

    The error message displays when field data missing but the button do not reveal hidden field when correct data is filled out in the required fields.

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

    (@codepeople)

    Hello @niklaskristiansson

    I’m not sure how you configured the fields because you did not provide the URL to the form. But if you have a field with two class names, kontaktuppgifter and hide, the code would be:

    
    if(jQuery(this.form).valid()) jQuery('.kontaktuppgifter').removeClass('hide');
    

    Without *

    Best regards.

    Thread Starter niklaskristiansson

    (@niklaskristiansson)

    ah sorry, here is the link: https://flyttfirma.net/test-kakylator20045/

    I found that the code works fine, but the reason it’s not working for me, is the fact that I’m hiding a div with some required fields inside. The div is hidden through assigning classes: kontaktuppgifter & hide

    When I click my button to reveal this div with fields inside, I think the button won’t reveal the div, due to the required fields inside the hidden div.

    Is there a way to make the hidden fields non-required while hidden and then required when revealed?

    Plugin Author codepeople

    (@codepeople)

    Hello @niklaskristiansson

    To make a field required or not by coding, you need to add or remove the required class name, respectively.

    Like:

    if(jQuery(this.form).valid()) 
    {
    jQuery('.kontaktuppgifter').removeClass('hide');
    jQuery('.kontaktuppgifter :input').addClass('required');
    }
    

    If you need some one that implement custom behaviors on your form, you can contact us directly through the plugin’s website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter niklaskristiansson

    (@niklaskristiansson)

    Ah thanks, now it works fine!

    Thanks for the super fast reply!

    Best Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘If field valid then reveal button’ is closed to new replies.