/**
  * Initializes the widget.
  * This method will publish JUI assets if necessary.
  * It will also register jquery and JUI JavaScript files and the theme CSS file.
  * Added for multiple support: some callback JS functions
  */
 public function init()
 {
     parent::init();
     // ensure assets are published
     // add a couple JS functions used by the callbacks
     $js = "function split( val ) {\n        if(val) {\n          return val.split( /{$this->delimiter}\\s*/ );\n        }\n        return [];\n      }\n      function extractLast( term ) {\n        if(term) {\n          return split( term ).pop();\n        }\n        return [];\n      }";
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#functions', $js);
 }
 public function init()
 {
     parent::init();
     // ensure necessary assets are loaded
     // JJD 8/3/11 make EJuiAutoCompleteFkField work for child rows where attribute like [$i]FieldName
     // get the ID which will be created for the actual field when it is rendered.
     // don't let resolveNameID() change $this->attribute which is needed to generate the actual field
     $attr = $this->attribute;
     $tempHtmlOpts = array();
     CHtml::resolveNameID($this->model, $attr, $tempHtmlOpts);
     $id = $tempHtmlOpts['id'];
     $this->_fieldID = $id;
     $this->_saveID = $id . '_save';
     $this->_lookupID = $id . '_lookup';
     $related = $this->model->{$this->relName};
     // get the related record
     $value = CHtml::resolveValue($this->model, $this->attribute);
     $this->_display = !empty($value) ? $related->{$this->displayAttr} : '';
     //	$this->_display=($value!==null ? $related->{$this->displayAttr} : ''); // nineinchnick comment #6809 handle zero as valid FK value. not sure works in all cases
     if (!isset($this->options['minLength'])) {
         $this->options['minLength'] = 2;
     }
     if (!isset($this->options['maxHeight'])) {
         $this->options['maxHeight'] = '100';
     }
     $this->htmlOptions['size'] = $this->autoCompleteLength;
     // fix problem with Chrome 10 validating maxLength for the auto-complete field
     $this->htmlOptions['maxlength'] = $this->autoCompleteLength;
     // setup javascript to do the work
     $this->options['create'] = "js:function(event, ui){\$(this).val('" . addslashes($this->_display) . "');}";
     // show initial display value
     // after user picks from list, save the ID in model/attr field, and Value in _save field for redisplay
     $this->options['select'] = "js:function(event, ui){\$('#" . $this->_fieldID . "').val(ui.item.id);\$('#" . $this->_saveID . "').val(ui.item.value);}";
     // when the autoComplete field loses focus, refresh the field with current value of _save
     // this is either the previous value if user didn't pick anything; or the new value if they did
     $this->htmlOptions['onblur'] = "\$(this).val(\$('#" . $this->_saveID . "').val());";
 }
 public function init()
 {
     parent::init();
     // ensure assets are published
     $this->_fieldName = get_class($this->model) . '_' . $this->attribute;
     // match what is generated by Yii
     $this->_saveName = $this->attribute . '_save';
     $this->_lookupName = $this->attribute . '_lookup';
     $related = $this->model->{$this->relName};
     // get the related record
     $this->_display = !empty($this->model->{$this->attribute}) ? $related->{$this->displayAttr} : '';
     if (!isset($this->options['minLength'])) {
         $this->options['minLength'] = 2;
     }
     if (!isset($this->options['maxHeight'])) {
         $this->options['maxHeight'] = '100';
     }
     if (!isset($this->options['select'])) {
         $this->options['select'] = '';
     }
     $this->htmlOptions['size'] = $this->autoCompleteLength;
     // fix problem with Chrome 10 validating maxLength for the auto-complete field
     $this->htmlOptions['maxLength'] = $this->autoCompleteLength;
     $this->htmlOptions['id'] = $this->_lookupName;
     $this->htmlOptions['name'] = $this->_lookupName;
     // setup javascript to do the work
     $this->options['create'] = "js:function(event, ui){\$(this).val('" . $this->_display . "');}";
     // show initial display value
     // after user picks from list, save the ID in model/attr field, and Value in _save field for redisplay
     $this->options['select'] = "js:function(event, ui){\$('#" . $this->_fieldName . "').val(ui.item.id);\$('#" . $this->_saveName . "').val(ui.item.value); " . $this->options['select'] . "}";
     // when the autoComplete field loses focus, refresh the field with current value of _save
     // this is either the previous value if user didn't pick anything; or the new value if they did
     $this->htmlOptions['onblur'] = "\$(this).val(\$('#" . $this->_saveName . "').val());";
 }