Question

I've an issue with validation groups.

When creating an user:

  • password can't be blank
  • passwordlength should be between 4 and 16 characters

When editing an user:

  • password can be blank
  • password 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.

Was it helpful?

Solution

Isn't the default group supposed to be used as Default with capital D?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top