diff --git a/demos/form/form.php b/demos/form/form.php index 25c27402d0..80dc4746e8 100644 --- a/demos/form/form.php +++ b/demos/form/form.php @@ -56,13 +56,16 @@ $group->addControl('surname'); $group->addControl('gender', [Form\Control\Dropdown::class, 'values' => ['Female', 'Male']]); +$accordionLayout = $form->layout->addSubLayout([Form\Layout\Section\Accordion::class]); +$details = $accordionLayout->addSection('Validating Field in Accordion'); + // testing 0 value $values = [0 => 'noob', 1 => 'pro', 2 => 'dev']; $form->addControl('description', [Form\Control\Textarea::class])->set(0); $form->addControl('no_description', [Form\Control\Textarea::class])->set(null); $form->addControl('status_optional', [Form\Control\Dropdown::class, 'values' => $values]); -$form->addControl('status_string_not-nullable', [Form\Control\Dropdown::class], ['type' => 'string', 'values' => $values, 'nullable' => false]); -$form->addControl('status_integer_not-nullable', [Form\Control\Dropdown::class], ['type' => 'integer', 'values' => $values, 'nullable' => false]); +$details->addControl('status_string_not-nullable', [Form\Control\Dropdown::class], ['type' => 'string', 'values' => $values, 'nullable' => false]); +$details->addControl('status_integer_not-nullable', [Form\Control\Dropdown::class], ['type' => 'integer', 'values' => $values, 'nullable' => false]); $form->addControl('status_string_required', [Form\Control\Dropdown::class], ['type' => 'string', 'values' => $values, 'required' => true]); $form->addControl('status_integer_required', [Form\Control\Dropdown::class], ['type' => 'integer', 'values' => $values, 'required' => true]); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 20e7b22418..07aef3bd83 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -87,6 +87,9 @@ parameters: - path: 'demos/form/form.php' message: '~^Call to an undefined method Atk4\\Ui\\JsChain::checkbox\(\)\.$~' + - + path: 'demos/form/form.php' + message: '~^Call to an undefined method Atk4\\Ui\\Form\\Layout::addSection\(\)\.$~' - path: 'demos/form/form2.php' message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::addAction\(\)\.$~' diff --git a/src/AccordionSection.php b/src/AccordionSection.php index 79f1342c88..7c84487f60 100644 --- a/src/AccordionSection.php +++ b/src/AccordionSection.php @@ -22,12 +22,17 @@ class AccordionSection extends View /** @var string */ public $icon = 'dropdown'; + /** @var string */ + public $warningIcon = 'exclamation circle'; + protected function renderView(): void { parent::renderView(); $this->template->set('icon', $this->icon); + $this->template->set('warningIcon', $this->warningIcon); + if ($this->title) { $this->template->set('title', $this->title); } diff --git a/src/Form.php b/src/Form.php index 248dc88618..f843b52eb8 100644 --- a/src/Form.php +++ b/src/Form.php @@ -260,6 +260,11 @@ public function onSubmit(\Closure $callback) $response = []; foreach ($e->errors as $field => $error) { $response[] = $this->error($field, $error); + + // If field inside Accordion section does not validate, open first AccordionSection + if ($this->getControl($field)->getOwner()->getOwner() instanceof \Atk4\Ui\AccordionSection) { + $response[] = $this->getControl($field)->getOwner()->getOwner()->getOwner()->js(true)->find('i.icon.atk-panel-warning.exclamation.circle')->addClass('atk-visible'); + } } return $response; diff --git a/template/accordion-section.html b/template/accordion-section.html index fdfd8514da..5b3ebe3711 100644 --- a/template/accordion-section.html +++ b/template/accordion-section.html @@ -1,5 +1,5 @@ -