Validation - user needs to complete at least one field of a table...

Avatar

Avatar

ellis355

Avatar

ellis355

ellis355

17-06-2015

Hi All

I have a table, which is populated by the user using dropdowns. I have some javascript which auto populates to the right of the users selection.

This all works fine however I now need to add some validation to check that the user has completed at least one field on one line.

The table is below

tableimpacts.JPG

So the validation (mandatory) needs to error unless at least one field is populated (in the dropdown section ie not 'Notes' or 'Date')

The pdf can be found here:

Dropbox - 207 For Forum.pdf

Any suggestions on the best method / cleanest code to make this happen?

Cheers

Ellis

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

jasotastic81

Avatar

jasotastic81

jasotastic81

19-06-2015

I suggest a Boolean called complete initialized to false, then loop through the fields in the right column (3 months) and if the field is not null, set the bool to true. Then check the bool and if it's true, you know at least one thing was filled in.


var complete = false;


//since you named all of the cells individually, we just have to look through each one.


if (!FinanceImpact7.isNull) complete = true;


if (!HealthSafetyImpact7.isNull) complete = true;


//etc...


if (!ReputationSatekholders7.isNull) complete = true;


if (complete) {


  //do whatever you would if it's complete


}


else {


  //do whatever you would do if it is NOT complete


}