What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How can I keep a quick tools multi-field question required, but have some of the sub fields be optional?

    Asked by GAPTAOnline on July 03, 2014 at 07:46 PM

    I was able to do this for the address line 2 field as I believe that this field should generally be optional, and I still want the user to be able to enter it, but I needed to have the address field as a whole required.

    There are several ways this can be done, but ultimately, when you require a field, the required check, among other checks are added by the setFieldValidation function.  You have to jsut add a rule to ignore that field type.  How this rule is defined will depend on your own requirements, but be sure that you are only matching the fields you want to be made optional.  The check could be specific to a single instance, or be general as in the address line 2 example that follows:

    Look for the two lines here in jotform.js and add the code below:
                               var innerVals = e.className.replace(/.*validate\[(.*)\].*/, '$1').split(/\s*,\s*/);
                               if(innerVals.include('required') && JotForm.isVisible(e)){

                                if(e.hasClassName("form-address-line") && e.id.indexOf("2") != -1) {//WE DON'T CARE ABOUT ADDR 2
                                e.removeClassName('form-validation-error');
                                e.__skipField = true;
                                return false;
                                }

    What this if statement does is it matches any element with the class "form-address-line" which matches both address line 1 and address line 2, but then it also requires that the id contains the number 2 which eliminates the address line 1 from being matched, giving us just all address line 2 elements.  If the element being checked is matched, then it clears the form-validation-error class, tells JotForm to skip this field, and returns false indicating no problem with the field.  There may be addition work involved for other field types, but this should give you a good place to start.

    Please feel free to correct me if my interpretation is wrong, or if there are any problems with this implementation I may have missed.  I hope it isn't a issue I posted a question I already had an answer to.  I just struggled with this for a while and I thought others might be having similar issues.

    tools JotForm address field problem check
  • Profile Image
    JotForm Support

    Answered by Welvin on July 03, 2014 at 10:20 PM

    Hi,

    Thank you for the information. That should help the others who needs the same function to the form. This is a great workaround.

    Allow me to forward this thread to our developers as a feature request. I am sure this a great addition to our existing validation rules. However, we cannot guarantee you a timeframe for its implementation. If there are updates, you should know via this thread.

    Thank you very much!