Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Require All Columns of List Field

$
0
0

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.

View this code snippet on GitHub.

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)?

Require All Columns on All Forms

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();

Require All Columns on a Specific Form

To apply this to a specific form, you would simply pass the form ID as the first parameter:

new GWRequireListColumns(4);

Require All Columns on a Specific Field

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);

Require All Columns on a Group of Fields

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) );

Require Specific Columns on a Group of Fields

To require specific columns on a specific field, you would specific the form ID, the field ID and the specific columns (by index, starting with 1) you would like to require:

new GWRequireListColumns( 240, 1, array( 2, 3 ) );

Note: If you have used new GWRequireListColumns() to require all columns on all fields, you can override which columns are required for a specific field by passing the $require_columns parameter in a new instance of this class.

Summary

This can be conveniently used in combination with the Set Number of List Field Rows by Field Value snippet.


Viewing all articles
Browse latest Browse all 196

Trending Articles