0
votes

Basically, my model requires that an object is tied to a physical location. For this I'm pulling locations from an API via AJAX using keywords entered by a user in a text field, jQuery autocomplete is setup to set a hidden field to a unique ID when the user selects a valid location recommended to them.

This is all fine, assuming the user has JavaScript and clicks a location.

I need to implement a fallback, i.e. for whatever reason, if the form is submitted without the hidden field having a value, the form should use whatever is in the visible to query the API and present a select box for users to choose a value from.

I know roughly the code I need to add, but I'm lost as to where to bind it in. Any help appreciated.

1

1 Answers

0
votes

Essentially you have to create a custome widget and use it in place of the locations form field. You can then add you javascript to the widgets rendering. If you extend sfWidgetChoice or the doctrine equivalent it will default to a select box. Then if js is enabled your widget's js will rewrite the field to an auto complete.

Have a look at the sfFormExtraPlugin for some great examples of how to do this.