You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ValidationScope: User unfriendly implementation #111
How does this help me when I have those countries loaded using AJAX and have $select->checkAllowedValues = FALSE;? I need to disable scope validation for that select for the submit to work.
Because I am stupid, $select->setPrompt() is what I needed, not to disable validation scope. But I still think that disabling the scope per field would be better.
@dg I have to disable validation scope when I use $select->setRequired();, $select->setPrompt() is not applicable in this case.
The problem is when I submit form with AJAX data, the value of select is outside $data variable, I have to get it using $form->getHttpData() which is okay but the form fails to submit because value of select is required and there is none in the time of checking.
I am back to my initial issue, disabling validation scope in this way is not friendly.
@juniwalk Because if you don't want the value to be validated, you should not make the select box required. What's the point of setting validation rules if they should be ignored?
@JanTvrdik In this context I ment the requirement validation as i use this to suggest user names and I get back just int (user Id) which I then in the onSuccess (probably not properly done but that is how I use it).
I'm sorry, I still don't understand it. How could you use the server-side validation when the select box is not validated at all because it is not included in the validation scope? What did I miss?
@dg So I tried that array_diff_key and it throws an error PHP Warning: array_diff_key(): Argument #1 is not an array in ./app/forms/ProductForm.php:136
EDIT: I'd have to combine it with iterator_to_array(). Having $select->disableValidationScope('submit'); would be really lovely.
Hi,
I revisited this old issue. Now when I am more skilled in Nette I basically never modify validationScope, I do my own validation in onValidate event.
I was modifying it before to keep the clientSide validation so user gets alerted before submitting that he did not select something required, however I can live without it.
Activity
dg commentedon Feb 17, 2016
What about condition?
juniwalk commentedon Feb 17, 2016
How does this help me when I have those countries loaded using AJAX and have
$select->checkAllowedValues = FALSE;? I need to disable scope validation for that select for the submit to work.Sorry if I haven't made myself clear about that.
dg commentedon Feb 19, 2016
Why you need to disable scope validation for select?
juniwalk commentedon Feb 20, 2016
Because I am stupid,
$select->setPrompt()is what I needed, not to disable validation scope. But I still think that disabling the scope per field would be better.juniwalk commentedon Feb 25, 2016
@dg I am closing this as it is probably unnecessary to have it here.
juniwalk commentedon Mar 2, 2016
@dg I have to disable validation scope when I use
$select->setRequired();,$select->setPrompt()is not applicable in this case.The problem is when I submit form with AJAX data, the value of select is outside
$datavariable, I have to get it using$form->getHttpData()which is okay but the form fails to submit because value of select is required and there is none in the time of checking.I am back to my initial issue, disabling validation scope in this way is not friendly.
dg commentedon Apr 1, 2016
Can you try to implement any solution?
juniwalk commentedon Apr 1, 2016
@dg Well I have a few ideas
First idea
$validateScopeproperty toBaseControlwhich will be bool.$control->disableValidationScope();// just examplesSubmitButtoncontrol? Is that possible? That would cause problems.Second idea
Nette\Forms\ValidationScopeBuilder\Traversableor extend\ArrayObject$vsb->disableScopeFor('control');$submit->setValidationScope($vsb);setValidationScopewill iterate over them.Third idea
What do you think? Does any of those sound good?
JanTvrdik commentedon Jun 19, 2016
Why not just set
$select->checkAllowedValues = FALSE? Redesigning validation scope seems like overkill.EDIT: Seems like we would need to modify
ChoiceControl::getValue()to respect$checkAllowedValuesas well. What do you think?EDIT: No we can't do it, it would be a BC break.
juniwalk commentedon Jun 19, 2016
@JanTvrdik Yeah, it is particularly troubling issue this one. I don't mind working with validation scope, it's just not very intuitive to work with.
JanTvrdik commentedon Jun 19, 2016
I don't think that validation scopes should be used for this kind of issue at all.
Another random idea
juniwalk commentedon Jun 20, 2016
Really? Why?
With your another random idea, I see potential problem with setting default value for editing.
JanTvrdik commentedon Jun 20, 2016
@juniwalk Because if you don't want the value to be validated, you should not make the select box required. What's the point of setting validation rules if they should be ignored?
juniwalk commentedon Jun 20, 2016
@JanTvrdik I do want the value validated, and I need it to be required, but that does not play well with AJAX values feeded in to the select box ...
JanTvrdik commentedon Jun 20, 2016
Could you elaborate on what exactly and where do you validate?
juniwalk commentedon Jun 20, 2016
@JanTvrdik In this context I ment the requirement validation as i use this to suggest user names and I get back just int (user Id) which I then in the onSuccess (probably not properly done but that is how I use it).
JanTvrdik commentedon Jun 20, 2016
I'm sorry, I still don't understand it. How could you use the server-side validation when the select box is not validated at all because it is not included in the validation scope? What did I miss?
juniwalk commentedon Jun 20, 2016
@JanTvrdik Ignore it, we diverged from the problem here, validation is not the issue, getting the value is.
juniwalk commentedon Jun 20, 2016
@JanTvrdik Yes, and to disable the scope is absolute horrendous work to do (especially for large forms).
dg commentedon Jun 20, 2016
->setValidationScope(array_diff_key($form->getControls(), ['country' => TRUE]))is horrendous?edit:
$form->getControls()returns ArrayIterator, soiterator_to_array($form->getControls()).juniwalk commentedon Jun 20, 2016
@dg Hey, now that looks much better, would you mind if I send PR to docs with this example to help others like me?
dg commentedon Jun 20, 2016
Of course I'll be happy. But try it please, I wrote from my head.
juniwalk commentedon Jun 22, 2016
@dg So I tried that array_diff_key and it throws an error
PHP Warning: array_diff_key(): Argument #1 is not an array in ./app/forms/ProductForm.php:136EDIT: I'd have to combine it with
iterator_to_array(). Having$select->disableValidationScope('submit');would be really lovely.juniwalk commentedon Mar 13, 2024
Hi,
I revisited this old issue. Now when I am more skilled in Nette I basically never modify validationScope, I do my own validation in onValidate event.
I was modifying it before to keep the clientSide validation so user gets alerted before submitting that he did not select something required, however I can live without it.
I think we can close this issue.
dg commentedon Oct 28, 2026
Closing as agreed.
onValidateor a filtered list of controls passed tosetValidationScope()covers the need.