/** * @param \inkvizytor\FluentForm\Base\Field $control */ public function control(Field $control) { $this->name($control->getName()); $this->help($control->getHelp()); $this->label($control->getLabel(), $this->isSrOnly()); $this->required($control->isRequired()); $this->setAttr($control->getAttr(null)); $this->setData($control->getData(null)); $this->css($control->getCss()); $width = $control->getWidth(); $this->width(array_get($width, 'lg'), array_get($width, 'md'), array_get($width, 'sm'), array_get($width, 'xs')); $this->control = $control; }
/** * @param \inkvizytor\FluentForm\Base\Field $control * @return bool */ public function isRequired(Field $control) { $rules = array_get($this->rules, $control->getName(), []); return $control->isRequired() || (is_array($rules) ? array_has($rules, 'required') : str_contains($rules, 'required')); }
/** * @param Field $control * @return string */ private function renderErrors(Field $control) { foreach ($this->getErrorMessages($control->getName()) as $message) { $name = str_replace('_', ' ', Str::snake($control->getName())); $label = $control->getLabel() ? $control->getLabel() : $control->getPlaceholder(); $message = str_replace($name, $label, $message); // Return only first error return sprintf('<label class="error" for="%s">%s</label>', $control->getName(), $message); } return ''; }
/** * @param Field $control * @return string */ private function renderErrors(Field $control) { foreach ($this->getErrorMessages($control->getName()) as $message) { $name = str_replace('_', ' ', Str::snake($control->getName())); $label = $control->getLabel() ? $control->getLabel() : $control->getPlaceholder(); $message = str_replace($name, $label, $message); // Return only first error return $this->html()->tag('label', ['for' => $control->getName(), 'class' => 'error'], $message); } return ''; }
/** * @param Field $control * @param string $class * @return string */ private function fieldLabel(Field $control, $class = null) { $attributes = ['for' => $control->getName()]; if ($control->isSrOnly()) { $class = trim($class . ' sr-only'); } if (!empty($class)) { $attributes['class'] = $class; } $label = $control->getLabel(); if (!empty($label)) { if ($this->isRequired($control)) { $label .= ' ' . $this->html()->tag('var', ['class' => 'required'], '*'); } return $this->html()->tag('label', $attributes, $label); } return null; }