Tagged: conditional
- This topic has 1 reply, 2 voices, and was last updated 5 years, 6 months ago by
Tonny Keuken.
-
AuthorPosts
-
-
July 20, 2016 at 6:13 pm #6985
morganrtMemberHello,
I can’t seem to get an HTML field to appear conditionally in a plugin I’m writing.I’ve got a radio with two options and an HTML field. The HTML field should only appear after someone clicks a radio button. In conditions, I’ve been using an empty value => ” or value => ‘none’ (preset in the choice field) along with compare => ‘!=’. Nothing I try with != works.
I’m not sure if it is intended behaviour, but ‘none’ only works if it is one of the choices. I only wanted to use it as the default, not make it a user choosable option.
There are numerious possible choice fields beyond the radio button I mention above, so I’d like to avoid trying to put in all options. There will only ever be one choice to determine whther the HTML should appear. It works much better to say ‘don’t show this if that field’s value is empty or not set or otherwise not one of its choices’.
An example choice field:
piklist('field',array( 'type' => 'radio', 'field' => 'response_structured', 'label' => 'Response', 'scope' => 'comment_meta', 'list' => false, 'choices' => array( 'yes' => 'Yes', 'no' => 'No' ), 'required' => true );The conditional field:
piklist('field', array( 'type' => 'html', 'field' => 'recorder', 'label' => 'A label...', 'help' => 'This is help text.', 'scope' => 'comment_meta', 'reset' => 'false', 'value' => '<div>Some HTML goes here</div>', 'conditions' => array( array( 'field' => 'response_structured', 'scope' => 'comment_meta', 'value' => '', 'compare' => '!=' )) ));I’ve left a lot of stuff in that I’ve tried with and without. Scope, reset and value seem to make no difference. Nothing I do with compare works.
-
July 25, 2016 at 11:57 am #7017
Tonny KeukenMemberHi morganrt,
Did you try to compare with the code below, already?
piklist('field', array( 'type' => 'html', 'field' => 'recorder', 'label' => 'A label...', 'help' => 'This is help text.', 'scope' => 'comment_meta', 'reset' => 'false', 'value' => '<div>Some HTML goes here</div>', 'conditions' => array( array( 'field' => 'response_structured', 'scope' => 'comment_meta', 'value' => array( '', null ), //This will compare against an empty string and no value at all 'compare' => '!=' )) ));Kind regards,
Tonny
-
-
AuthorPosts
- You must be logged in to reply to this topic.