Skip to content

Commit c7eeb84

Browse files
committed
Change what decides whether the email additional text container should be open
It was a `class=hidden` on the container itself, checking form component's value to see if it should be added or not. Now it's `class=expanded` on an element defined by `data-class-target`, a textarea in this case, where `class=expanded` is added in the form factory if needed. CSS `:has()` is currently not supported by Firefox (it's behind a flag) but guess that's ok by me. Fixes ``` ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------ Line Compiled Admin/Presenters/templates/Emails/default.latte rendered from MichalSpacekCz\Admin\Presenters\EmailsPresenter::default line See compiled template: /tmp/phpstan-latte/app/Admin/Presenters/templates/Emails/default.latte.ffc5a80775bd006bd5dcca69684ee311.php ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------ 63 364 Cannot access offset 'additional' on Nette\Forms\Controls\BaseControl. ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------ ```
1 parent b85ad94 commit c7eeb84

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

site/app/Admin/Presenters/templates/Emails/default.latte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<td></td>
6161
<td colspan="5">{input feedbackRequest}</td>
6262
</tr>
63-
<tr n:class="expand-container, !$form[applications][$application->id][additional]->value ? hidden">
63+
<tr class="expand-container" data-class-target="textarea">
6464
<td></td>
6565
<td></td>
6666
<td colspan="5">

site/app/Form/TrainingMailsOutboxFormFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function create(callable $onSuccess, array $applications): Form
3939
$form = $this->factory->create();
4040

4141
$applicationsContainer = $form->addContainer('applications');
42+
$additionalInputs = [];
4243

4344
foreach ($applications as $application) {
4445
$applicationIdsContainer = $applicationsContainer->addContainer($application->id);
@@ -101,7 +102,7 @@ public function create(callable $onSuccess, array $applications): Form
101102
if ($sendCheckboxTitle) {
102103
$send->setHtmlAttribute('title', implode("\n", $sendCheckboxTitle));
103104
}
104-
$applicationIdsContainer->addTextArea('additional')
105+
$additionalInputs[] = $applicationIdsContainer->addTextArea('additional')
105106
->setHtmlAttribute('placeholder', 'Dodatečný text')
106107
->setHtmlAttribute('cols', 80)
107108
->setHtmlAttribute('rows', 3);
@@ -181,6 +182,13 @@ public function create(callable $onSuccess, array $applications): Form
181182
}
182183
$onSuccess($sent);
183184
};
185+
$form->onAnchor[] = function () use ($additionalInputs): void {
186+
foreach ($additionalInputs as $additionalInput) {
187+
if ($additionalInput->getValue()) {
188+
$additionalInput->setHtmlAttribute('class', 'expanded');
189+
}
190+
}
191+
};
184192
return $form;
185193
}
186194

site/public/www.michalspacek.cz/i/css/screen.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ div.notice {
376376
margin-left: 1.1em;
377377
line-height: 0;
378378
}
379+
#frm-mails .expand-container:not(:has(.expanded)) {
380+
display: none;
381+
}
379382
#frm-passwordsStorages #frm-passwordsStorages-algo-from { width: 200px; }
380383
#pubkey {
381384
background-color: #F7F7FF;

site/public/www.michalspacek.cz/i/js/admin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ App.ready(document, function () {
106106

107107
App.onClick('#emails tbody .button', function () {
108108
for (const item of this.parentElement.parentElement.querySelectorAll('.expand-container')) {
109-
item.classList.toggle('hidden');
109+
const classTarget = item.querySelector(item.dataset.classTarget);
110+
if (classTarget) {
111+
classTarget.classList.toggle('expanded');
112+
}
110113
}
111114
});
112115
App.onClick('#emails #checkAll', function (event) {

0 commit comments

Comments
 (0)