/** * Configures the current widget. * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetFormJQueryAutocompleter */ protected function configure($options = array(), $attributes = array()) { $this->addRequiredOption('model'); $this->addOption('method_for_query', 'findOneById'); $this->addOption('method', '__toString'); parent::configure($options, $attributes); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { $str_values = $this->getValues($value, $name); return parent::render($name, null, $attributes, $errors) . sprintf(<<<EOF <input id="add-button" type="button" value="%s" onClick="addItem()" style="margin-left:5px;"/> <div id="ajax-loader" style="display:none; padding:5px;"> %s </div> <div id="items-list"> <h3 style="margin:0; padding:0;">%s</h3> <ul id="autocomplete-list"> {$str_values} </ul> </div> <script type="text/javascript"> function addItem() { var id = jQuery('#{$this->generateId($name)}').val(); if((jQuery('#item-'+id).text()=='')&&(id!='')) jQuery.ajax({ url: '%s', data: 'id=' + id, cache: false, dataType: 'json', beforeSend: function() { jQuery("#ajax-loader").show(); jQuery("#add-button").hide(); }, complete: function() { jQuery("#ajax-loader").hide(); jQuery("#add-button").show(); }, error: function(xhr, status, error) { alert(xhr.status); }, success: function(data) { var item = "<li id='item-" + id + "'>" + data[id]; item += "<a href='#' onClick='deleteItem("+ id +")'> %s </a>"; item += "<input id='{$this->generateId($name)}_" + id + "' name='{$name}[]' type='hidden' value='" + id + "'/> </li>"; jQuery('#autocomplete-list').append(item); } }); } function deleteItem(object_id) { jQuery.ajax({ url: '%s', data: 'id=' + object_id, beforeSend: function() { jQuery('#ajax-loader').show(); }, complete: function() { jQuery('#ajax-loader').hide(); }, success: function(data) { jQuery('#item-'+object_id).remove(); } }); } </script> EOF , $this->getOption('button_label'), $this->getOption('indicator'), $this->getOption('list_title'), $this->getOption('save_method'), preg_replace('/\\"/', "'", $this->getOption('undo_image')), $this->getOption('delete_method')); }
protected function configure($options = array(), $attributes = array()) { $this->addRequiredOption('search_attr'); parent::configure($options, $attributes); }