From 621d33fb35e563e3154a067d4fb2f1ec997131f2 Mon Sep 17 00:00:00 2001 From: Michael Krecek Date: Sun, 28 Aug 2022 07:37:47 +0200 Subject: [PATCH 1/6] Open first accordion if validation exception of control inside --- demos/form/form.php | 8 ++++++-- src/Form.php | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/demos/form/form.php b/demos/form/form.php index 25c27402d0..02954aa762 100644 --- a/demos/form/form.php +++ b/demos/form/form.php @@ -38,6 +38,7 @@ Header::addTo($tab, ['Very simple form']); $form = Form::addTo($tab); + $form->addControl('email'); $form->onSubmit(function (Form $form) { // implement subscribe here @@ -56,13 +57,16 @@ $group->addControl('surname'); $group->addControl('gender', [Form\Control\Dropdown::class, 'values' => ['Female', 'Male']]); +$accordionLayout = $form->layout->addSubLayout([\Atk4\Ui\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/src/Form.php b/src/Form.php index 248dc88618..f4b84087aa 100644 --- a/src/Form.php +++ b/src/Form.php @@ -258,7 +258,14 @@ public function onSubmit(\Closure $callback) return $response; } catch (ValidationException $e) { $response = []; + $openFirstSectionOnError = false; + foreach ($e->errors as $field => $error) { + if (!$openFirstSectionOnError && $this->getControl($field)->getOwner()->getOwner() instanceof \Atk4\Ui\AccordionSection) { + $response[] = $this->getControl($field)->getOwner()->getOwner()->getOwner()->jsOpen($this->getControl($field)->getOwner()->getOwner()); + $openFirstSectionOnError = true; + } + $response[] = $this->error($field, $error); } From 70d6bde62c2105854ef7e7fc42c46ea78fd3c111 Mon Sep 17 00:00:00 2001 From: Michael Krecek Date: Sun, 28 Aug 2022 09:08:25 +0200 Subject: [PATCH 2/6] Further changes --- src/Form.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Form.php b/src/Form.php index f4b84087aa..3c2d584c68 100644 --- a/src/Form.php +++ b/src/Form.php @@ -261,12 +261,14 @@ public function onSubmit(\Closure $callback) $openFirstSectionOnError = false; foreach ($e->errors as $field => $error) { + $response[] = $this->error($field, $error); + + // If field inside Accordion section does not validate, open first AccordionSection if (!$openFirstSectionOnError && $this->getControl($field)->getOwner()->getOwner() instanceof \Atk4\Ui\AccordionSection) { $response[] = $this->getControl($field)->getOwner()->getOwner()->getOwner()->jsOpen($this->getControl($field)->getOwner()->getOwner()); $openFirstSectionOnError = true; } - $response[] = $this->error($field, $error); } return $response; From 39fb4b4bb34c9b563b9f5949c097c9c6bc1d6ccf Mon Sep 17 00:00:00 2001 From: Michael Krecek Date: Mon, 29 Aug 2022 09:57:01 +0200 Subject: [PATCH 3/6] Fix CS, phpstan --- demos/form/form.php | 3 +-- phpstan.neon.dist | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/demos/form/form.php b/demos/form/form.php index 02954aa762..80dc4746e8 100644 --- a/demos/form/form.php +++ b/demos/form/form.php @@ -38,7 +38,6 @@ Header::addTo($tab, ['Very simple form']); $form = Form::addTo($tab); - $form->addControl('email'); $form->onSubmit(function (Form $form) { // implement subscribe here @@ -57,7 +56,7 @@ $group->addControl('surname'); $group->addControl('gender', [Form\Control\Dropdown::class, 'values' => ['Female', 'Male']]); -$accordionLayout = $form->layout->addSubLayout([\Atk4\Ui\Form\Layout\Section\Accordion::class]); +$accordionLayout = $form->layout->addSubLayout([Form\Layout\Section\Accordion::class]); $details = $accordionLayout->addSection('Validating Field in Accordion'); // testing 0 value diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 20e7b22418..71e945d7e9 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\(\)\.$~' From 7ae4051016fc8daef8c2a09df6b08bf22aa12bd6 Mon Sep 17 00:00:00 2001 From: Michael Krecek Date: Mon, 29 Aug 2022 09:59:19 +0200 Subject: [PATCH 4/6] Fix CS --- src/Form.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Form.php b/src/Form.php index 3c2d584c68..069053206c 100644 --- a/src/Form.php +++ b/src/Form.php @@ -268,7 +268,6 @@ public function onSubmit(\Closure $callback) $response[] = $this->getControl($field)->getOwner()->getOwner()->getOwner()->jsOpen($this->getControl($field)->getOwner()->getOwner()); $openFirstSectionOnError = true; } - } return $response; From 4fac97a98eb0a076ff6391eb548de7383b1de92c Mon Sep 17 00:00:00 2001 From: Michael Krecek Date: Mon, 29 Aug 2022 10:02:48 +0200 Subject: [PATCH 5/6] Fix phpstan --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 71e945d7e9..07aef3bd83 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -89,7 +89,7 @@ parameters: 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\(\)\.$~' + 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\(\)\.$~' From 14bf730415ad7c84f076d95cc12671ce748b0084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 29 Aug 2022 15:13:21 +0200 Subject: [PATCH 6/6] WIP warning icon --- src/AccordionSection.php | 5 +++++ src/Form.php | 7 ++----- template/accordion-section.html | 2 +- template/accordion-section.pug | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) 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 069053206c..f843b52eb8 100644 --- a/src/Form.php +++ b/src/Form.php @@ -258,15 +258,12 @@ public function onSubmit(\Closure $callback) return $response; } catch (ValidationException $e) { $response = []; - $openFirstSectionOnError = false; - foreach ($e->errors as $field => $error) { $response[] = $this->error($field, $error); // If field inside Accordion section does not validate, open first AccordionSection - if (!$openFirstSectionOnError && $this->getControl($field)->getOwner()->getOwner() instanceof \Atk4\Ui\AccordionSection) { - $response[] = $this->getControl($field)->getOwner()->getOwner()->getOwner()->jsOpen($this->getControl($field)->getOwner()->getOwner()); - $openFirstSectionOnError = true; + 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'); } } 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 @@ -
{title}Title{/}
+
{title}Title{/}
{$Content}
diff --git a/template/accordion-section.pug b/template/accordion-section.pug index 13cbf6bc53..7b0df518b9 100644 --- a/template/accordion-section.pug +++ b/template/accordion-section.pug @@ -1,5 +1,6 @@ div(id="{$_id}" class="title") i(class="{$icon} icon") + i(class="atk-panel-warning {$warningIcon} icon") | {title}Title{/} div(class="content ui basic segment", data-path="{$path}", style="min-height: 60px") div(id="{$itemId}")