jquery – Is there any better / better / better way to approach this input verifier?

Actually, I got a form with multiple entries (around 39) in which I want to perform some checks and display customs messages based on a set of conditions.

I found a way to address my problem, but I wonder (and I'm pretty sure it exists) if there is a better way to address this.

My problem comes from the fact that there are many custom fields to which I must address (many entries to verify with a custom error viewer per entry and, sometimes, more than a personalized message to send / show), plus a large number of verification to perform.

hideShowError (elem, sub) {function
sub = sub || false;
parentElem = getBoxParent ($ (elem), sub);

yes (parentElem! = false)
parentElem.addClass (& # 39; errorWrapper & # 39;);

false return;
}

hideShowErrorWithMessage function (elem, message, special, sub, noBorder) {
sub = sub || false;
special = special || false;
noBorder = noBorder || false;
parentElem = getBoxParent ($ (elem), sub);

if (parentElem! = false) {
parentElem.addClass (& # 39; errorWrapper & # 39;);
yes
parentElem.addClass (& # 39; errorWrapper-no-border & # 39;);
parentElem.find (& # 39 ;. errorSpe & # 39;). text (message);
special? parentElem.find (& # 39 ;. disable-error & # 39;). addClass ("active"): parentElem.find (& # 39 ;. disable-error-pb & # 39;). removeClass ("active");
}

false return;
}

getBoxParent function (childElem, sub) {
childElem = childElem || "";
sub = sub || false;

if (childElem! = "") {
yes (! sub)
return childElem.closest (& # 39 ;. questBox3 & # 39;);
return childElem.closest (& # 39 ;. subQuestBox3 & # 39;);
}
false return;
}

function testInput () {
var input1 = $ (& # 39; input1-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input1-f & # 39;). is (& # 39 ;: marked & # 39;);
var input2 = $ (& # 39; input2-f & # 39;). is (& # 39 ;: checked & # 39;);
var input3 =! $ (& # 39; input3-t & # 39;). is (& # 39 ;: checked & # 39;) &&! $ (& # 39; input2-f & # 39;). is (& # 39 ;: checked & # 39;);
var input4 = $ (& # 39; input4-f & # 39;). is (& # 39 ;: checked & # 39;);
var input5 =! $ (& # 39; input5-t & # 39;). is (& # 39 ;: checked & # 39;) &&! $ (& # 39; input4-f & # 39;). is (& # 39 ;: checked & # 39;);
var input6 = $ (& # 39; input6-f & # 39;). is (& # 39 ;: checked & # 39;);
var input7 =! $ (& # 39; input7-t & # 39;). is (& # 39 ;: checked & # 39;) &&! $ (& # 39; input6-f & # 39;). is (& # 39 ;: checked & # 39;);
var input8 = $ (& # 39; input8-f & # 39;). is (& # 39 ;: checked & # 39;);
var input9 =! $ (& # 39; input9-t & # 39;). is (& # 39 ;: checked & # 39;) &&! $ (& # 39; input8-f & # 39;). is (& # 39 ;: checked & # 39;);
var input10 = $ (& # 39; input10-t & # 39;). is (& # 39 ;: checked & # 39;);
var input11 =! $ (& # 39; input11-f & # 39;). is (& # 39 ;: checked & # 39;) &&! $ (& # 39; input10-t & # 39;). is (& # 39 ;: checked & # 39;);
var input12 = $ (& # 39; input12-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input12-f & # 39;). is (& # 39 ;: check & # 39;);
var input13 = $ (& # 39; input13-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input13-f & # 39;). is (& # 39 ;: marked & # 39;);
var input14 = $ (& # 39; input14-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input14-f & # 39;). is (& # 39 ;: marked & # 39;);
var input15 = $ (& # 39; input15-f & # 39;). is (& # 39 ;: checked & # 39;);
var input16 = $ (& # 39; input16select option: selected & # 39;). length> 0 && $ (& # 39; input16select option: selected & # 39;). val ()! = 0;
var input17 = $ (& # 39; input17select option: selected & # 39;). length> 0 && $ (& # 39; input17select option: selected & # 39;). val ()! = 0;
var input18 = $ (& # 39; input18 & # 39;). val () length> 0;
var input19 = $ (& # 39; input19 & # 39;). val () length> 0;
var input20 = $ (& # 39; input20 & # 39;). val () length> 0;
var input21 = $ (& # 39; input21 & # 39;). val () length> 0;
var input22 = $ (& # 39; input22 & # 39;). val () length> 0;
var input23 = $ (& # 39; input23 & # 39;). val () length> 0;
var input24 = $ (& # 39; input24 & # 39;). val () length> 0;
var input25 = $ (& # 39; input25-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input25-f & # 39;). is (& # 39 ;: marked & # 39;);
var input26 = $ (& # 39; input26-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input26-f & # 39;). is (& # 39 ;: marked & # 39;);
var input27 = $ (& # 39; input27-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input27-f & # 39;). is (& # 39 ;: check & # 39;);
var input28 = $ (& # 39; input28 & # 39;). val () length> 0 || $ (& # 39; input28-2 & # 39;). val () length> 0 || $ (& # 39; input28-3 & # 39;). val () length> 0;
var input29 = $ (& # 39; input29-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input30-f & # 39;). is (& # 39 ;: marked & # 39;);
var input30 = $ (& # 39; input30-f & # 39;). is (& # 39 ;: checked & # 39;);
var input31 = $ (& # 39; input31-t & # 39;). is (& # 39 ;: checked & # 39;) || $ (& # 39; input32-f & # 39;). is (& # 39 ;: check & # 39;);
var input32 = $ (& # 39; input32-f & # 39;). is (& # 39 ;: checked & # 39;);
var input33 = $ (& # 39; input33 & # 39;). val () length> 0;
var input34 = $ (& # 39; input33 & # 39;). val ()! = "" && (! $. isNumeric ($ (& # 39; input33 & # 39;). val ()) || ($ (& # 39; input33 & # 39;). val ()> 99 || $ ( & # 39; input33 & # 39;). Val () <0));

// input check box
var input35 = $ (& # 39; input35: checked & # 39;). length;
var input36 = $ (& # 39; input36: checked & # 39;). length;

// siret control
var numSiret = ($ (& # 39; input28 & # 39;). val (). toString ()). replace (/  s + / g, & # 39; & # 39;);

var validSiret = ("" == numSiret || (verif_siren_siret (numSiret, 9) && verif_siren_siret (numSiret, 14)))

// Get CP (97, 971, 972 ...)
var departement = & # 39;<%= @adresse.try(:departement) %>& # 39; .match ("^ 97");

// Error checking Question 1 (input)
yes (! entry1)
ret = hideShowError (& # 39; input1-t & # 39;);
// Error checking Question 9 (entry)
yes (input2 &&! input3)
ret = hideShowErrorWithMessage (& # 39; input2-f & # 39 ;,<%= t('sometrad1') %>", false, false, true);
// Checking errors Question 10 (input)
yes (input4 &&! input5)
ret = hideShowErrorWithMessage (& # 39; input4-f & # 39 ;,<%= t('sometrad1') %>", false, false, true);
// Checking errors Question 11 (entry)
yes (input6 &&! input7)
ret = hideShowErrorWithMessage (& # 39; input6-f & # 39 ;,<%= t('sometrad1') %>", false, false, true);
// Checking errors Question 12 (entry)
yes (input8 &&! input9)
ret = hideShowErrorWithMessage (& # 39; input8-f & # 39 ;,<%= t('sometrad1') %>", false, false, true);
// Checking errors Question 13 (entry)
yes (input10 &&! input11)
ret = hideShowErrorWithMessage (& # 39; input10-t & # 39 ;,<%= t('sometrad1') %>", false, false, true);

yes (! input2 && input3)
ret = hideShowErrorWithMessage (& # 39; input2-f & # 39 ;,<%= t('sometrad2') %>", false);
yes (! input4 && input5)
ret = hideShowErrorWithMessage (& # 39; input4-f & # 39 ;,<%= t('sometrad2') %>", false);
yes (! input6 && input7)
ret = hideShowErrorWithMessage (& # 39; input6-f & # 39 ;,<%= t('sometrad2') %>", false);
yes (! input8 && input9)
ret = hideShowErrorWithMessage (& # 39; input8-f & # 39 ;,<%= t('sometrad2') %>", false);
yes (! input10 && input11)
ret = hideShowErrorWithMessage (& # 39; input10-t & # 39 ;,<%= t('sometrad2') %>", false);
yes (! input12)
ret = hideShowError (& # 39; input12-t & # 39;);
if ($ (& # 39; input12-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input13)
ret = hideShowErrorWithMessage (& # 39; input13-t & # 39 ;,<%= t('sometrad2') %>", false true);
yes (! entry14)
ret = hideShowErrorWithMessage (& # 39; input14-t & # 39 ;,<%= t('sometrad2') %>", false true);
yes (entry15)
ret = hideShowErrorWithMessage (& # 39; input13-t & # 39 ;,<%= t('sometrad3') %>", false true);
yes (! input16)
ret = hideShowError (& # 39; input16select & # 39;);
yes (! input17)
ret = hideShowError (& # 39; input17select & # 39;);
yes (entry18)
ret = hideShowError (& # 39; input18 & # 39;);
yes (! input19)
ret = hideShowError (& # 39; input19 & # 39;);
yes (! input25)
ret = hideShowError (& # 39; input25-t & # 39;);
yes ($ (& # 39; input25-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input20)
ret = hideShowError (& # 39; input20 & # 39;);
yes ($ (& # 39; input25-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input21)
ret = hideShowError (& # 39; input21 & # 39;);
if ($ (& # 39; input25-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input22)
ret = hideShowError (& # 39; input22 & # 39;);
yes ($ (& # 39; input25-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input23)
ret = hideShowError (& # 39; input23 & # 39;);
if ($ (& # 39; input25-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input24 && null! = department)
ret = hideShowError (& # 39; input24 & # 39;);
yes (! entry26)
ret = hideShowError (& # 39; input26-t & # 39;);
yes (input26 &&! input27)
ret = hideShowErrorWithMessage (& # 39; input27-t & # 39 ;,<%= t('sometrad2') %>", false);
yes ($ (& # 39; input27-t & # 39;). is (& # 39 ;: marked & # 39;) &&! input28) {
ret = hideShowErrorWithMessage (& # 39; input28 & # 39 ;,<%= t('sometrad4') %>", false);
ret = hideShowErrorWithMessage (& # 39; input28-2 & # 39 ;,<%= t('sometrad4') %>", false);
ret = hideShowErrorWithMessage (& # 39; input28-3 & # 39 ;,<%= t('sometrad4') %>", false);
}
if ($ (& # 39; input27-t & # 39;). is (& # 39 ;: check & # 39;) && $ (& # 39; input28 & # 39;). val (). length> 0 &&! validSiret)
ret = hideShowErrorWithMessage (& # 39; input28 & # 39 ;,<%= t('sometrad5') %>", false);

// Error Check Question 13 (check box)
yes (entry35> 0)
ret = hideShowErrorWithMessage (& # 39; # pb-decence-1 & # 39 ;,<%= t('sometrad2') %>", false, false, true);
if (input35 == 0 && input36 == 0)
ret = hideShowErrorWithMessage (& # 39; # pb-decence-1 & # 39 ;,<%= t('sometrad2') %>", false);

yes (! input29)
ret = hideShowErrorWithMessage (& # 39; input29-t & # 39 ;,<%= t('sometrad2') %>", false);
yes (entry 30)
ret = hideShowErrorWithMessage (& # 39; input29-t & # 39 ;,<%= t('sometrad6') %>", false);

yes (! input31)
ret = hideShowErrorWithMessage (& # 39; input31-t & # 39 ;,<%= t('sometrad2') %>", false);
yes (input32)
ret = hideShowErrorWithMessage (& # 39; input31-t & # 39 ;,<%= t('sometrad7') %>", false, false, true);

yes (! input33)
ret = hideShowErrorWithMessage (& # 39; input33 & # 39 ;,<%= t('sometrad8') %>", false);
yes (entry34)
ret = hideShowErrorWithMessage (& # 39; input33 & # 39 ;,<%= t('sometrad2') %>", false);
}

I also add a block of HTML code (thin), although all the entries are not the same, the general structure is almost the same

div.questGridWrapper
div.questBox
span = t (& # 39; quest_9 & # 39;)
div.questBox
span.special-info
span = t (& # 39; quest_error_warn.warn_0 & # 39;) + ""
            
        
        
        
        div.no-display-info
br
span = t (& # 39; quest_9_prec.sub_1 & # 39;)
br
br
ul
li.li-style
span = t (& # 39; input.sub_2 & # 39;)
span.color O
li.li-style
span = t (& # 39; input.sub_3 & # 39;)
div.questGridWrapper
div.questBox3
div.form-group.radio_buttons
div.form-check-hacked

span.radio
tag for = "t-entry"
- if @ pb_projet_courant.pb_logement.espace_suffisant == true
input.form-check-input.radio_buttons type = "radio" name = "input[value]"check =" check "id =" input-t "value =" true "
= t (& # 39; generic.quest_yes & # 39;)
another thing
input.form-check-input.radio_buttons type = "radio" name = "input[value]"id =" input-t "value =" true "
= t (& # 39; generic.quest_yes & # 39;)

span.radio
tag for = "input-f"
- if @ pb_projet_courant.pb_logement.espace_suffisant == false
input.form-check-input.radio_buttons type = "radio" name = "input[value]"checked =" checked "id =" input-f "value =" false "
= t (& # 39; generic.quest_no & # 39;)
another thing
input.form-check-input.radio_buttons type = "radio" name = "input[value]"id =" input-f "value =" false "
= t (& # 39; generic.quest_no & # 39;)

.Error message
span.errorSpe.errorSpe-noBorder = t (& # 39; someDefaultTrad & # 39;)

(I had to anonymize the code before publishing it, so, unfortunately, getting an example may take a few times, but the code itself works, I'm looking for ways to improve my claims if there is any information on the number of conditions that are verified .