Closed ajaxovic closed 4 years ago
Can you try last commit?
Revision 2e3d657e79 does not work
Nette\MemberAccessException
Call to undefined method WebChemistry\Forms\Controls\Multiplier::getCreateButtons(), did you mean addCreateButton()?
Problematic code (generated in cache):
<?php
$_multiplier = end($this->global->formsStack)["rows"];
if (isset($_multiplier->getCreateButtons()[1])) {$_input = $_multiplier->getCreateButtons()[1];
echo $_input->getControl()->addAttributes(['class' => 'ajax prepareLines']);
}
?>
cache deleted..
now?
Sorry for delay...
Textbox works now, but problem is with prompt on select:
$container->addSelect('parent_id', 'Parent', $this->names)
->setPrompt('Choose parent');
When I hit add button, exception appears:
Value '' is out of allowed set [1, 2, 3, 10] in field 'parent_id'
When I remove prompt, all works. Checked out commit: b1c11b7000c1da818f653f82550e909e303b60aa
Sorry, this is built-in behavior of nette select box :/
Thanks for answer.
Are you sure? Validation work when select is not in Multiplier...
Are you sure? This is still issue...
Ah, sorry.
Problem code is
$multiplier = $form->addMultiplier('rows', function (Nette\Forms\Container $container, Nette\Forms\Form $form) {
$container->addSelect('parent_id', 'Parent', $this->names)
->setPrompt('Choose parent');
}
with new version?
Mam rovnaky problem. Ak do selectu pridam ->setPrompt(...) nette hlasi chybu Value '' is out of allowed set [0] in field
at dev-master
problem still persist
I have problem with validation on createButton. I tried to set ->setNoValidate()
and ->setValidationScope(null)
, but on + button form is still validating.
Thank you for the fix, but problem still persist at latest dev-master.
@BigOHenry I fix only Value '' is out of allowed set [0] in field
not validation on createButton. I tried
protected function createComponentMultiplier() {
$form = new Form();
$form['multiplier'] = $mul = new Multiplier(function (Container $container) {
$container->addText('name')
->setRequired();
});
$mul->addCreateButton()
->setNoValidate();
$form->addSubmit('send');
return $form;
}
and it works, please send your code
/** @var Multiplier $containers */
$containers = $form->addMultiplier($itemGroup->getName(), function (Container $container) use ($itemGroup) {
$container->addInteger(
'sequence_priority',
$this->translator->translate('config.definition.sequence_priority')
)
->setRequired($this->translator->translate("forms.validation.required"))
->setOption('group_name', $itemGroup->getName())
->setOption('example', '')
->setOption('note', '');
/** @var ItemDefinition $itemDefinition */
foreach ($itemGroup->getItemDefinitions() as $itemDefinition) {
$translated_item_definition = $this->translator->translate('config.definition.' . $itemDefinition->getName());
$container->addText($itemDefinition->getName(), $translated_item_definition)
->setOption('group_name', $itemGroup->getName())
->setOption('example', $itemDefinition->getExample())
->setOption('note', $itemDefinition->getNote());
if ($itemDefinition->isNotNull()) {
$container[$itemDefinition->getName()]
->setRequired($this->translator->translate("forms.validation.required"));
}
}
$container->addHidden('dummy_format')->setOption('group_name', $itemGroup->getName());
}, 0);
/** @var \Nette\Application\UI\Presenter $presenter */
$presenter = $this;
$containers->addCreateButton('', 1)
->setNoValidate()
->setValidationScope([])
->addOnCreateCallback(
function (Submitter $submitter) use ($presenter, $itemGroup) {
$submitter->setHtmlAttribute('class', 'btn-success btn-sm fad fa-plus ajax ' . $itemGroup->getName() . '-multiplier-creator-config config-recurring-add-button');
$submitter->setOption('group_name', $itemGroup->getName());
$submitter->onClick[] = function () use ($presenter) {
$presenter->redrawControl('configForm');
};
}
);
@BigOHenry I tried your code and all works. Which version of nette / contributte/forms-multiplier (commit) do you have?
Does submit button have attribute formnovalidate?
Is validation on client or server side?
I have my own onValidate ($form->onValidate[] = array($this, 'onValidate');
) validations. On multiplier add button is called onValidate too. I think with setNoValidate()
should be onValidate skipped too.
Thank you!
https://doc.nette.org/en/3.0/form-validation#toc-disabling-validation
onValidate event on the form is always invoked and is not affected by the setValidationScope. onValidate event on the container is invoked only when this container is specified for partial validation.
Is this issue resolved? I'm having trouble with Value '' is out of allowed set [...] in field xy
Used version: "contributte/forms-multiplier": "^3.0"
Code:
...
$list = $form->addMultiplier('list', function (Container $container, Nette\Forms\Form $form) {
$container->addSelect( 'select', 'Pick one' , ['a' => 'a', 'b' => 'b'] )
->setPrompt('')
->setRequired(true);
}, 0);
$list ->addRemoveButton('Remove', function (SubmitButton $submitter) use ($self) {
$submitter->setValidationScope(false);
$submitter->onClick[] = [$self, 'onClick'];
});
...
Steps to reproduce error:
createButton
to add new copy and fill out all inputscreateButton
again and leave inputs empty (especially select
)removeButton
and voilaIf you need some more info to resolve it. I'll be happy to help.
I have:
Composer.json
updated at e9983931f9
Form factory:
In generated HTML code, there is
But when I click twice od add button, nette
$form->hasErrors()
contains validation error 'Please, fill name'I expect no validation on add button, user can add multiple rows and then fill them...