/** * @param $value \gromver\models\fields\BaseField * @return array|null */ protected function validateValue($value) { if ($this->required && !count($value->getValue())) { return [$this->requiredMessage ? $this->requiredMessage : Yii::t('gromver.models', 'Field {attribute} can\'t be empty.'), []]; } if (!$this->model->validate()) { return [$this->message ? $this->message : Yii::t('gromver.models', 'Field {attribute} contains no valid items.'), []]; } }
/** * @param Yii\widgets\ActiveForm $form * @return string */ protected function renderExtraFields($form) { if ($this->extra <= 0) { return ''; } $model = new ArrayModel($this->model, $this->_fieldConfig); $model->on(BaseModel::EVENT_FORM_NAME, [$this, 'prefixedFormName']); $extra = $this->extra; $index = count($this->_value); while ($extra--) { $model[$index++] = null; } $fields = $model->modelFields(); $html = ''; /** @var $field \gromver\models\fields\BaseField */ foreach ($fields as $field) { $html .= strtr('<div class="grom-field-multiple-field grom-field-multiple-field_extra">{remove}{down}{up}{field}</div>', ['{field}' => $field->field($form), '{up}' => Html::button('<i class="glyphicon glyphicon-chevron-up"></i>', ['class' => 'grom-field-multiple-up-btn']), '{down}' => Html::button('<i class="glyphicon glyphicon-chevron-down"></i>', ['class' => 'grom-field-multiple-down-btn']), '{remove}' => Html::button('<i class="glyphicon glyphicon-remove"></i>', ['class' => 'grom-field-multiple-close-btn'])]); } return $html; }