wp-shortcake / shortcake

Shortcake makes using WordPress shortcodes a piece of cake.
GNU General Public License v2.0
664 stars 142 forks source link

Conditionally display a field based on value of another field #333

Open danielbachhuber opened 9 years ago

danielbachhuber commented 9 years ago

A request from the forums:

After clicking the ShortcodeUi's shortcode edit button in the editor, shortcodeUi should display an select list with options like "button", "CTA Button" & "Share Button".

If user selects "CTA button" then ShortcodeUI should display "CTA_id" field. If user selects "Share Button" then ShortcodeUI should display "Share_id" field.

Fieldmanager has some display_if flag we could emulate.

goldenapples commented 9 years ago

I think that this can be covered along with #316, as I imagine a lot of the same use cases for each. Registering a js callback function with the shortcode ui that receives the new value and has access to the collection to modify it would be one way of accomodating this.

goldenapples commented 9 years ago

The system of JS actions introduced in #336 makes this possible. Do we want a syntactic sugar for this specific use case, so that an attribute in the shortcode UI registration array can generate the javascript event listener to show/hide fields conditionally? Or is letting authors register their own js callbacks sufficient? Either way, this will need some documentation.

danielbachhuber commented 9 years ago

Do we want a syntactic sugar for this specific use case, so that an attribute in the shortcode UI registration array can generate the javascript event listener to show/hide fields conditionally?

Not at this time. The Fieldmanager implementation is actually a bit buggy, so I don't see value in copying it 1:1.

Either way, this will need some documentation.

Pull request against readme.txt?