My custom widget’s form will have two pull-down menus: the content of the second menu is dependent on the user’s selection in the first menu (think of the way Country and State/Province works).
I think the easiest implementation (though perhaps not the most user-friendly) would simply be to have the form automatically submit itself when the first pulldown is changed (ie: <select onchange="submit_the_page_via_ajax()">
). I tried onchange="this.form.submit();"
but that didn’t leverage the Ajax call to my surprise (I would have thought that the sophisticated WordPress developers would have hiJaxed the form’s submit event). They must be hijaxing the submit button however, since all my view source shows me is a standard html input type for the button.
Anyway, I would appreciate a little insight into a best practice for submitting a widget’s form leveraging ajax. This is a great post but only addresses the widget’s display, not the back-end form.
The Save buttons have a class
widget-control-save
, and this is hooked up towpWidgets.save()
. So you either have to callwpWidgets.save()
, or (probably easier) trigger a click event on the Save button.