Tagged: conditionals
- This topic has 19 replies, 5 voices, and was last updated 6 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
December 11, 2014 at 11:21 am #3049
egamipeaksMemberI am trying to create a show/hide toggle from a nested add_more group, and having trouble getting it to toggle the fields. The bottom two selects are supposed to toggle based on the first select value.
piklist( 'field', array( 'type' => 'group', 'label' => 'Location Rules', 'description' => 'Create a set of rules to determine which pages will load this Ad Unit.', 'field' => '_ad_unit_location_rules', 'add_more' => true, 'fields' => array( array( 'type' => 'html', 'field' => 'secret', 'label' => 'Rule Group', 'columns' => 12, 'value' => '' ), array( 'type' => 'group', 'field' => 'location_group', 'add_more' => true, 'fields' => array( array( 'type' => 'select', 'field' => 'location_page', 'label' => 'Page Condition', 'columns' => 12, 'attributes' => array( 'class' => 'field_location_page' ), 'choices' => array( 'post_type' => 'Post Type', 'page' => 'Page' ) ), array( 'type' => 'select', 'field' => 'location_comparison', 'label' => 'Comparison', 'columns' => 12, 'choices' => array( '==' => 'Is equal to', '!=' => 'Is not equal to' ) ), array( 'type' => 'select', 'field' => 'location_options_post_type', 'label' => 'Post Type Options', 'columns' => 12, 'attributes' => array( 'class' => 'field_location_options' ), 'choices' => array( 'op1' => 'Option 1', 'op2' => 'Option 2' ), 'conditions' => array( array( 'field' => '_ad_unit_location_rules:location_group:location_page', 'value' => 'post_type' ) ) ), array( 'type' => 'select', 'field' => 'location_options_page', 'label' => 'Page Options', 'columns' => 12, 'attributes' => array( 'class' => 'field_location_options' ), 'choices' => array( 'op1' => 'Option 1', 'op2' => 'Option 2' ), 'conditions' => array( array( 'field' => '_ad_unit_location_rules:location_group:location_page', 'value' => 'page' ) ) ) ) ) ) )); -
December 11, 2014 at 2:21 pm #3059
SteveKeymasterLooks like we have a bug with conditions inside two groups. This one may take a while to fix.
-
December 11, 2014 at 2:44 pm #3061
egamipeaksMemberOk, please keep me informed if you can
-
March 22, 2015 at 3:54 am #3492
Jan ČejkaMemberHello,
do you have any idea about when will it work?I need a working version this week.
I do not know if I should wait or find another solution.Thanks 🙂
-
March 22, 2015 at 11:29 am #3493
SteveKeymasterPlease post your field code here.
-
March 27, 2015 at 9:02 pm #3528
natchrissMemberI noticed that you can’t have a field “monitored” twice. I.e. (i) to show/hide a field AND (ii) to update another field.
Quick example: We have a “US States” select field with one option being “I’m not from US”. If that option is selected, a textbox is shown for manual input of state/province. That condition works.
We have another textbox called “Country”.
If we wanted to monitor the “US States” field (again) to auto-update the “Country” field to ‘USA’ unless the “I’m not from US” is selected, we can’t.Don’t know if it’s a bug but I thought I had to mention it. 🙂
-
March 29, 2015 at 9:38 pm #3531
SteveKeymaster@natchriss– If I’m following you correctly, you can’t update a field that isn’t showing yet. If I don’t have this correct, please post your field code here so we can take a look.
-
March 30, 2015 at 12:41 pm #3535
natchrissMemberHi @Steve! First off, congrats to the team for the excellent work! I’m one of the “outsiders” who never used ACF, Types and the like just because I don’t want to be restricted by ‘their way of doing things’. So coding was the only option to maintain the WP way.
Now, what I said wasn’t about updating a hidden field. But not being able to monitor a field twice.
Let me replicate a code example using the same parameters as above:
piklist('field', array( 'type' => 'group' ,'label' => 'Address:' ,'fields' => array( array( 'type' => 'text' ,'field' => 'address' ,'label' => 'Street Address:' ,'columns' => 12 ) ,array( 'type' => 'select' ,'field' => 'state' ,'label' => 'State:' ,'columns' => 4 ,'choices' => array( 'CA' => 'California' ,'NY' => 'New York' ,'DC' => 'District of Columbia' ,'TX' => 'Texas' ,'Non-US' => 'Not from USA' ) /** The part that won't work IF we also have * the other condition on the next field */ // Start: --> ,'conditions' => array( array( 'type' => 'update' ,'value' => 'Non-US' ,'compare' => '!=' ,'field' => 'country' ,'update' => 'USA' ) ) // <-- End ) ,array( 'type' => 'text' ,'field' => 'state_other' ,'label' => 'State/Province/Region:' ,'columns' => 4 ,'conditions' => array( array( 'field' => 'state' 'value' => 'Non-Us' ) ) ) ,array( 'type' => 'text' ,'field' => 'country' ,'label' => 'Country:' ,'columns' => '4' ) ) ));In this quick example we have a field (
state_other) hidden and only shown when the “Non-US” option is selected from thestatefield. That’s the first time we monitor the latter. So far so good.Now, if we wanted to monitor the
statefield [with our other condition in place] to update the last field (country) [i.e. monitor the same field twice], we can’t.Makes sense now?
I figured that you’re intentionally not allowing “double monitoring” to prevent other issues (?), but since I found a case that it’d be useful, I thought I should mention it.
PS – Irrelevant: On another note, are all HTML form attributes supported? Could we use
autocomplete' => 'on'for instance? -
December 1, 2015 at 8:57 am #5169
akamiseMemberHey guys. Is the issue in the original post fixed? Conditionals are not working for me if the trigger field is in a nested group(so
'field' => 'group:field'works fine, but'field' => 'group:anothergroup:field'isn’t doing anything. I’m not sure if I’m bumping into the same known bug or it’s a new thing. -
December 1, 2015 at 2:07 pm #5170
-
December 1, 2015 at 2:18 pm #5171
akamiseMemberIt’s a nested addmore and I think there’s no other way around that. I’m making something similar to a page builder – An ‘addmore’ that adds a ‘row’ to the page, and nested addmores that add blocks of various sizes to the row. The idea is that I need to have different types of blocks and some of them won’t need certain fields. The conditional functionality would be ideal in that case. The code is below. The issue is on line 79.
piklist('field', array( 'type' => 'group', 'field' => 'page-block-row', 'label' => __( 'Page blocks'), 'columns' => 12, 'add_more' => true, 'description' => __( 'Make sure the sizes of all blocks on a row add up to 1 or less(ex. 3/4 + 1/4 = 1). If you exceed 1, you will break the layout.', 'shtrak-blocks' ), 'fields' => array( array( 'type' => 'select', 'field' => 'row-height', 'columns' => 12, 'choices' => array( 'tall' => __( 'Tall', 'shtrak-types' ), 'short' => __( 'Short', 'shtrak-types' ), 'fullwidth' => __( 'Full Width', 'shtrak-types' ) ) ), array( 'type' => 'colorpicker', 'field' => 'row-background-color', 'label' => __( 'Background Color', 'shtrak-blocks' ), 'columns' => 12, 'conditions' => array( array( 'field' => 'page-block-row:row-height', 'value' => 'fullwidth' ) ) ), array( 'type' => 'group', 'field' => 'block', 'add_more' => true, 'fields' => array( array( 'type' => 'select', 'label' => __( 'Block Width', 'shtrak-blocks' ), 'field' => 'block-width', 'columns' => 6, 'choices' => array( 'one-half' => '1/2', 'three-fourths' => '3/4', 'full-width' => '1', 'one-fourth' => '1/4' ), ), array( 'type' => 'select', 'label' => __( 'Block Type', 'shtrak-blocks' ), 'field' => 'block-type', 'columns' => 6, 'choices' => array( 'type-1' => __( 'Type 1', 'shtrak-blocks' ), 'type-2' => __( 'Type 2', 'shtrak-blocks' ), 'type-3' => __( 'Type 3', 'shtrak-blocks' ), 'type-4' => __( 'Type 4', 'shtrak-blocks' ), 'social' => __( 'Social', 'shtrak-blocks' ) ) ), array( 'type' => 'text', 'label' => __( 'Title', 'shtrak-blocks' ), 'field' => 'block-title', 'columns' => 12 ), array( 'type' => 'text', 'label' => __( 'Subtitle', 'shtrak-blocks' ), 'field' => 'block-subtitle', 'columns' => 12, //below is the condition that's not working. 'conditions' => array( array( 'field' => 'page-block-row:block:block-type', 'value' => 'type-1' ) ) ), array( 'type' => 'textarea', 'field' => 'block-description', 'label' => __( 'Description', 'shtrak-blocks' ), 'columns' => 12 ), array( 'type' => 'text', 'field' => 'block-button-label', 'label' => __( 'Action button label', 'shtrak-blocks' ), 'columns' => 6 ), array( 'type' => 'text', 'field' => 'block-button-link', 'label' => __( 'Action button link', 'shtrak-blocks' ), 'columns' => 6 ) ) ) ) ));btw, piklist is great, thanks for that.
-
December 1, 2015 at 2:30 pm #5172
SteveKeymasterWhich version of Piklist are you using?
-
December 1, 2015 at 2:33 pm #5173
akamiseMemberIt’s the latest one from wordpress.org – 0.9.4.29, running on WordPress 4.3.1
-
December 1, 2015 at 2:36 pm #5174
SteveKeymasterThis issue is fixed in our latest beta v0.9.9x. You can grab it here.
Also, were so happy you think Piklist is great! Would you mind telling the world by leaving a quick 5 Star review on WordPress.org? It really helps the project.
-
December 1, 2015 at 2:37 pm #5175
egamipeaksMemberSteve, do you mean the original issue is fixed?
-
December 1, 2015 at 2:48 pm #5176
SteveKeymaster@egamipeaks– Your field as written above is still not working. But I’m also not sure if it’s written correctly.
1. What is the purpose of the field “secret”?
2. Why are there two add_mores? -
December 1, 2015 at 3:05 pm #5177
akamiseMember@Steve – Thanks a lot, you’re awesome. Unfortunaltely I’m having a weird issue with the db upgrade that the new version requires – `Active Plugin Versions Updated…
Legacy post_relationships Table Deleted…
Settings Updated…
piklist_core – shortcode_ui`
It’s been sitting like that for like 15 minutes. The piklist fields from the code above also dissapeared from the metabox. Is there anything I can do to repair this manually or I should restore a backup and try again?
I’ll let you guys both know if this fixes my original issue, when I get it running again.
As for the 5-star rating – I did that a very long time ago 🙂
-
December 1, 2015 at 3:21 pm #5178
SteveKeymaster@akamise– Would you be comfortable giving me access to your site? If so, please email a login and pw to [email protected]
-
December 1, 2015 at 3:49 pm #5181
akamiseMember@Steve – I’d do that but it’s a local environment(and vagrant share doesn’t like having a ton of wp instances apparently). Anyway, I managed to fix the issue by deleting piklist alltogether(the nice way – disable all plugins that depend on piklist; disable piklist; delete piklist) and then reinstalling it. The update procedure went fine and best of all, my original issue is fixed.
Thank’s a lot for the help, you’re great!
-
December 1, 2015 at 3:50 pm #5182
SteveKeymasterAwesome! Closing ticket.
-
-
AuthorPosts
- The topic ‘Nested groups and conditionals’ is closed to new replies.