Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Manny Fleurmond

    (@funkatronic)

    You can add validation rules to your meta box to specify features for individual fields, including whether or not a field is required. Notice the code in the demo file here: https://github.com/rilwis/meta-box/blob/d3d89945e60c464b9a6b9ecf5fcebcffe9782012/demo/demo.php#L130

    Thread Starter wpfan1000

    (@wpfan1000)

    Hi Manny,

    Thanks for your response.

    I did notice that validation example, but it seems to be for adding a password.

    I am more looking for simply a “required” setting.

    Is there an example anywhere of how to do that?

    Plugin Contributor Manny Fleurmond

    (@funkatronic)

    The validation example I linked does show how to do a required field. Look at line 140

    Thread Starter wpfan1000

    (@wpfan1000)

    Please look at the context of that line:

    Line 137: // optional override of default jquery.validate messages

    Line 140: ‘required’ => __( ‘Password is required’, ‘your-prefix’ ),

    In other words line 140 specifies text to over-ride the standard text associated with the password.

    Furthermore, the above lines are a subset of:

    ‘rules’ => array(
    “{$prefix}password” => array(
    ‘required’ => true,
    ‘minlength’ => 7,

    Which specifies a password, and has nothing to do with specifying a “required” setting.

    Just because you see “required” a bunch of times in some code does not mean it has anything to do with setting a “required” validation to a field.

    Furthermore, there is nothing I can find in that whole file that has anything to do with setting “required”.

    Plugin Contributor Manny Fleurmond

    (@funkatronic)

    Sorry, wrong line of code. password is the name of one of the fields. I’ve editted the code to make more sense:

    'validation' => array(
    	'rules'    => array(
    		"myfavecolor" => array(
    			'required'  => true,
    		),
    	),
    	// optional override of default jquery.validate messages
    	'messages' => array(
    		"myfavecolor" => array(
    			'required'  => __( 'Field is required', 'your-prefix' ),
    		),
    	)
    )

    The validation code creates a rule that makes the field of name myfavcolor required. The messages part is the message that is displayed if the user leaves the field blank

    Thread Starter wpfan1000

    (@wpfan1000)

    Thanks for adding that 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘"Required" setting’ is closed to new replies.