Isn't the default group supposed to be used as Default
with capital D
?
Validation groups for password change in Symfony 2?
-
27-06-2022 - |
Pregunta
I've an issue with validation groups.
When creating an user:
password
can't be blankpassword
length should be between 4 and 16 characters
When editing an user:
password
can be blankpassword
should be between 4 and 16 characters if it's filled
My user entity validation YAML, declaring the create
group:
My\Entity\User:
properties:
username:
- NotBlank: ~
- Length: { min: 4, max: 12 }
email:
- Email: ~
- Length: { max: 255 }
plainPassword:
- NotBlank:
groups: [create]
- Length: { min: 4, max 16 }
As far as I know default is the group containing all validators to belonging to any group (that is all but NotBlank
for password). Group create
contains only the NotBlank
rule for plainPassword
. So:
- creating:
default
+create
groups - editing:
default
group
I'm passig array('validation_groups' => array('default', 'create'))
when in my createAction
controller action, and array('validation_groups' => array('default'))
when editAction
is invoked.
It doesn't work: when editing the password can be blank (correct) but if it's filled no errors occurs if - say - it's 3 characters long.
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow