I have successfully implemented Autocomplete field from database using sfWidgetFormJQueryAutocompleter but i cannot a find a way to insert a new value if the listed values are not required.
Everytime i submit a form with new value, it shows me “required” error. It is due to the reason that the auto-complete field has a different name then the form widget.
my widget configuration is
'city' => new sfWidgetFormJQueryAutocompleter(array(
'url' => url_for('trainingdetail/ajaxcity'),
'config' => '{ width: 220,max: 5,highlight:false ,multiple: false,multipleSeparator: ",",scroll: true,scrollHeight: 300}'
))
I thought there may be a more elegant way of doing this, but i solved it as follows.
When using sfWidgetFormJqueryAutocompleter, the actual form field get replaced by another field from the widget and the original form field converts to a hidden field.
I simply checked if the visible field has a value, and if yes, assigns the value to the hidden field which is the original form fields defined in form class.
my sample code, triggers at form submit.
here :
#autocomplete_trn_training_cityis the id of field generated by jquery widgetand
#trn_training_cityis the id of original form field which is submitted to the database.