Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark all parent accordions/tabs if validation exception of control inside #1835

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions demos/form/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
mkrecek234 marked this conversation as resolved.
Show resolved Hide resolved

// 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]);

Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\(\)\.$~'
Expand Down
5 changes: 5 additions & 0 deletions src/AccordionSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion template/accordion-section.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<div class="title" id="{$_id}"><i class="{$icon} icon"></i>{title}Title{/}</div>
<div class="title" id="{$_id}"><i class="{$icon} icon"></i><i class="atk-panel-warning {$warningIcon} icon"></i>{title}Title{/}</div>
<div class="content ui basic segment" data-path="{$path}" style="min-height: 60px">
<div id="{$itemId}">{$Content}</div>
</div>
1 change: 1 addition & 0 deletions template/accordion-section.pug
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down