Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public static function error($model, $attribute, $options = [])
 {
     $attribute = static::getAttributeName($attribute);
     $tag = isset($options['tag']) ? $options['tag'] : 'div';
     unset($options['tag'], $options['formName']);
     // TODO: manage encode
     /*$encode = !isset($options['encode']) || $options['encode'] !== false;
       unset($options['encode']);*/
     $validators = $model->getActiveValidators($attribute);
     // Get all ng-message directives from the model
     $ngMessages = [];
     foreach (AngularValidator::getAngularValidators($validators) as $validator) {
         $ngMessages[] = static::ngMessages($validator, $model, $attribute);
     }
     $ngMessages[] = Html::tag('div', null, ['us-server-message' => true]);
     // Wrap up all ngMessages in a ng-messages directive
     $formName = $model->formName();
     $formNgModel = Html::getFormNgModel($model, $attribute);
     // Compute error showing condition
     $errorCondition = [];
     if (!isset($options['ifDirty']) || $options['ifDirty']) {
         $errorCondition[] = $formNgModel . '.$dirty';
         unset($options['ifDirty']);
     }
     if (!isset($options['ifTouched']) || $options['ifTouched']) {
         $errorCondition[] = $formNgModel . '.$touched';
         unset($options['ifTouched']);
     }
     $errorCondition = implode(' && ', $errorCondition);
     $ngMessages = Html::tag('div', implode("\n", $ngMessages), ['ng-messages' => $formNgModel . '.$error', 'ng-if' => '(' . $errorCondition . ')  || ' . $formName . '.$submitted']);
     return Html::tag($tag, $ngMessages, $options);
 }