When you mark a List field as required, only a single input from any column is required. What if you want every input in every column to be required? Here is a snippet that let’s you do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
How do I install this snippet?
Just copy and paste the code above in your theme’s ”functions.php” file.
Do I need to configure this snippet to work with my form(s)?
Only if you want to apply this functionality to specific forms and/or specific fields. A default instantiation of this class (with no parameters) will apply this functionality to all list fields on all forms.
new GWRequireListColumns();
To apply this to a specific form, you would simply pass the form ID as the first parameter:
new GWRequireListColumns(4);
To apply this functionality to a specific form and a specific List field on that form, you would specify the form ID as the first parameter and the field ID as the second:
new GWRequireListColumns(4, 2);
To apply this functionality to a specific form and multiple List fields on that form, you would specify the form ID as the first parameter and an array of fields IDs as the second parameter:
new GWRequireListColumns(4, array(2,3);
Summary
This can be conveniently used in combination with the Set Number of List Field Rows by Field Value snippet.