Viewing 7 reply threads
  • Author
    Posts
    • #5057
      tatamata
      Member

      Hello,

      I want to show required field only if condition is met. But even if condition is not met required field is still passed for validation. Any advice on how to work around this?

      piklist('field', array(
      	'type' => 'checkbox',
      	'field' => 'alone',
      	'label' => 'Alone?',
      	'choices' => array(
      		'yes' => 'Yes'
      	)
      ));
      
      piklist('field', array(
      	'type' => 'text',
      	'field' => 'another_one',
      	'required' => true,
      	'conditions' => array(
      		array(
      			'field' => 'alone',
      			'value' => 'yes'
      		)
      	)
      ));
      
    • #5070
      Steve
      Keymaster

      @tatamata– This is an issue with our required field and conditions. We are looking at ways to address this securely.

    • #5290
      fritsgarrer
      Member

      Isn’t it possible to add a ‘required’ subparameter to the ‘conditions’ parameter? And if used it overides the ‘required’ parameter in the field declaration.

      piklist('field', array(
      		'type' => 'text'
      		,'scope' => 'post_meta'
      		,'field' => 'name'
      		,'label' => __('Name')
      		,'required' => true //void if used within conditions parameter
      		,'conditions' => array(
      			array(
      				'field' => 'master-field'
      				,'value' => 'yes'
      				,'required' => true
      			)
      		)
      	));
    • #5294
      Steve
      Keymaster

      @fritsgarrer– Welcome to the Piklist community!

      required does not go in the conditions array. This is still an issue. However, a work around might be to put your fields under different tabs in a WorkFlow. You can easily wrap the field in a standard PHP conditional that way.

    • #5351
      fritsgarrer
      Member

      Unfortunately workflows is not a possibility for my use.

      Can you tell me why you choose not to put the possibility of “required” into the conditions array? I personally don’t see why it would be a bad thing. But maybe I’m thinking the wrong way for a sollution.

      btw what I forgot to say in my last post: Piklist is in my opinion the “one plugin to rule them all”. Where I used to have about 12 plugins I now only use Piklist and Yoast.

    • #5352
      abmcr
      Member

      I also need a required condition into a validation.
      May be as future feature in new version
      Thank you

    • #5356
      Steve
      Keymaster

      @fritsgarrer– It’s not that we choose not to, it’s just that we haven’t implemented yet. Currently, we are working on getting our unit tests complete and getting Piklist to v1.0. We want to implement this, but it’s a feature request, and we are holding off on feature requests until v1.0.

    • #8380
      vayu
      Member

      I miss this feature as well!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.