June 30, 2016 at 4:33 pm #6864morganrtParticipant
I’m new to Piklist, working on a simple plugin that creates a custom post with a couple of custom admin fields. An answer to this field determines whether another field appears on a public comment form.
Custom post type: Question, using the title field to write the question.
Custom admin only field: “response_type” (radio box with a few options)
Public comment form field: “response” (whether it’s yes or no, a rating, etc should be determined by the custom field in Question).
When I have conditional fields appear in the same file, they work as expected. In the case above, the response_type is in the metabox file with other Question related fields and only appears in admin. The conditional field appears in a separate comment_form-metabox.php file and when they are apart, they don’t work.
I found the post at the link below and thought the solution was adding scope to the conditions array and tried numerous scope combinations.
Example appears in question-metabox.php
piklist('field', array( 'type' => 'radio', 'field' => 'response_type', 'label' => 'Response Type', 'help' => 'This is help text.', 'scope' => 'post_meta', 'choices' => array( 'yn' => 'Yes or No', 'ad' => 'Agree or Disagree', 'Rating1toX' => 'Rating: 1 to X', 'RatingXto0toX' => 'Rating: -X to 0 to X' ), 'value' => 'yn', 'required' => true ));
Example appears in public facing comment_form_metabox.php
piklist('field', array( 'type' => 'radio', 'field' => 'response', 'label' => 'Response', 'scope' => 'comment_meta', 'list' => false, 'choices' => array( 'Yes' => 'Yes', 'No' => 'No' ), 'conditions' => array( array( 'scope' => 'post_meta', 'field' => 'response_type', 'value' => 'yn' )) ));
Hopefully, it’s easily fixed. I don’t discount the possibility I’ve misunderstood something and/or have been staring at this too long to see the obvious.
July 2, 2016 at 1:57 am #6873morganrtParticipant
UPDATE: I haven’t got the piklist code working yet but I’ve managed a workaround by grabbing the value of the first field and using it in a conditional to produce the required second field. It’s not as elegant or extensible as the piklist code could be but it seems to work for now.
From the lack of comment here, I’m guessing I haven’t explained the problem well or it’s maybe more difficult than I originally thought.
July 5, 2016 at 10:57 am #6885
- You must be logged in to reply to this topic.