getClientOptions() protected method

Returns the JS options for the field.
protected getClientOptions ( ) : array
return array the JS options.
 /**
  * Useful to test other methods from ActiveField, that call ActiveField::getClientOptions()
  * but it's return value is not relevant for the test being run.
  */
 public function getClientOptions()
 {
     return $this->getClientOptionsEmpty ? [] : parent::getClientOptions();
 }
Beispiel #2
0
 /**
  * Returns the JS options for the field.
  * @return array the JS options
  */
 public function getClientOptions()
 {
     return parent::getClientOptions();
 }
 protected function getClientOptions()
 {
     $options = [];
     $attribute = Html::getAttributeName($this->attribute);
     if (!in_array($attribute, $this->model->activeAttributes(), true)) {
         return [];
     }
     $validators = [];
     foreach ($this->model->getActiveValidators($attribute) as $validator) {
         /* @var $validator \yii\validators\Validator */
         $js = $validator->clientValidateAttribute($this->model, $attribute, $this->form->getView());
         if ($validator->enableClientValidation && $js != '') {
             if ($validator->whenClient !== null) {
                 $js = "if (({$validator->whenClient})(attribute, value)) { {$js} }";
             }
             $validators[] = $js;
         }
     }
     if (!empty($validators)) {
         $options['validate_extra'] = new JsExpression("function (attribute, value, messages, deferred, \$form) {" . implode('', $validators) . '}');
     }
     return array_merge($options, parent::getClientOptions());
 }