[wp-trac] [WordPress Trac] #36944: Display server-sent Customizer setting validation errors before save is attempted

WordPress Trac noreply at wordpress.org
Mon Jun 13 20:48:55 UTC 2016


#36944: Display server-sent Customizer setting validation errors before save is
attempted
--------------------------------------+--------------------------
 Reporter:  westonruter               |       Owner:  westonruter
     Type:  defect (bug)              |      Status:  accepted
 Priority:  normal                    |   Milestone:  4.6
Component:  Customize                 |     Version:  trunk
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+--------------------------

Comment (by NateWr):

 I had a quick test with the demo plugin. I really like it. A couple of
 thoughts:

 1. It can be a little bit disorienting the way that the preview falls back
 to the currently saved value. For instance, I title a widget `Hello` and
 then save it. Then I type `Hello World` and see it in the preview. Then I
 add a `!` and the preview goes back to showing `Hello`. I don't think it's
 a critical problem, especially since the error message appears there. But
 can still feel a bit odd. If it could show the last valid value that'd be
 great.

 2. Skimming the code in the diff and the demo plugin, it looks like JS
 `Setting` objects now have a `Notification` object attached, and these are
 passed to a control, which has a `renderNotifications` method. So to
 render a validation error in a custom control we just need to do some work
 in the `renderNotifications` method, correct? That seems pretty
 straightforward if correct, and if I understand the code correctly it
 seems like errors will be announced (`wp.ally.speak`) prior to this,
 meaning we don't need to reproduce that. Very nice.

 3. I'm wondering how I would go about extending a `Notification` object's
 `data` param. For my use case, I have a kind of "uber" `Control`. It saves
 to a single `Setting`, but in the process it compiles a bunch of different
 input fields into a single serialized string. So for me, the setting id
 won't be sufficient for determining where to display the error message. I
 would need additional params attached to the `Notification`. It seems to
 include a `data` param which looks like it is where extra data could be
 attached, but I'm not seeing anything in `api._handleSettingValidities`
 that would allow me to attach extra params. Can you point me to what I'm
 missing?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36944#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list