diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index bac909df..a9cbe41f 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -239,6 +239,7 @@ public function getControl() 'required' => $this->isRequired(), 'disabled' => $this->isDisabled(), 'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: null, + 'form' => $el->form ?? $this->getForm()->getElementPrototype()->id, ]); } diff --git a/src/Forms/Controls/Button.php b/src/Forms/Controls/Button.php index 021bbcc7..dd4c5647 100644 --- a/src/Forms/Controls/Button.php +++ b/src/Forms/Controls/Button.php @@ -59,9 +59,11 @@ public function getControl(string|Stringable|null $caption = null): Html { $this->setOption('rendered', true); $caption = $this->translate($caption ?? $this->getCaption()); - $el = (clone $this->control)->addAttributes([ + $el = clone $this->control; + $el->addAttributes([ 'name' => $this->getHtmlName(), 'disabled' => $this->isDisabled(), + 'form' => $el->form ?? $this->getForm()->getElementPrototype()->id, ]); if ($caption instanceof Html || ($caption !== null && $el->getName() === 'button')) { $el->setName('button')->setText($caption); diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index 2f5dd812..bcbb18e0 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -84,6 +84,7 @@ public function getControl(): Html 'name' => $this->getHtmlName(), 'disabled' => $this->isDisabled(), 'value' => (string) $this->value, + 'form' => $el->form ?? $this->getForm()->getElementPrototype()->id, ]); } diff --git a/tests/Forms/Forms.form.phpt b/tests/Forms/Forms.form.phpt new file mode 100644 index 00000000..83e51b3e --- /dev/null +++ b/tests/Forms/Forms.form.phpt @@ -0,0 +1,31 @@ +getElementPrototype()->id = 'frmid'; + +$form->addText('a'); +$form->addTextArea('b'); +$form->addDate('c'); +$form->addUpload('d'); +$form->addHidden('e'); +$form->addCheckbox('f'); +$form->addRadioList('g', null, ['item']); +$form->addCheckboxList('h', null, ['item']); +$form->addSelect('i'); +$form->addMultiSelect('j'); +$form->addColor('k'); +$form->addSubmit('l'); +$form->addButton('m'); +$form->addImageButton('n'); +$form->addHidden('none')->setHtmlAttribute('form', false); +$form->addHidden('diff')->setHtmlAttribute('form', 'different'); + +Assert::matchFile(__DIR__ . '/expected/Forms.form.expect', $form->__toString(true)); diff --git a/tests/Forms/expected/Forms.form.expect b/tests/Forms/expected/Forms.form.expect new file mode 100644 index 00000000..f0ef62eb --- /dev/null +++ b/tests/Forms/expected/Forms.form.expect @@ -0,0 +1,72 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
\ No newline at end of file