add UniqueFieldValidator #242

Open
ienzam opened this Issue Jun 24, 2013 · 5 comments

Projects

None yet

3 participants

ienzam commented Jun 24, 2013

UniqueFieldValidtor can check a field for uniqueness, so that we can do

Some\DemoBundle\Model\User:
    properties:
        username:
            - Propel\PropelBundle\Validator\Constraints\UniqueField:
                message: some.custom.message
ienzam commented Jun 24, 2013

Yes, but the documentation lacks how to bind it to a specific field, the constraint is bound to the whole object.
Is there any way to bind it to a field?

Also is there is any way to write constraint to the property like other constraints? That will be easy to understand.

mpiecko commented Jun 24, 2013

Yes you're right. You can use it only on the whole class. But this is usefull if you're validating more than one field to be unique. If you want to display an error message beside the "username" field you can use the "errorPath" option:

    ....
    'errorPath' => 'username'
    ....
ienzam commented Jun 24, 2013

Ok thanks, that works 👍
I had written an validator for UniqueField, guess I don't need this anymore.
Should I close this issue?

mpiecko commented Jun 24, 2013

I think you should leave it to the core devs. Maybe this coud be a feature for an upcoming release to bind this constraint to a field directly. :)

Michael

@havvg havvg added the Enhancement label Jan 22, 2016
@havvg havvg added this to the 1.5 - Symfony 2.8 LTS support milestone Jan 22, 2016
@havvg havvg changed the title from An UniqueFieldValidator to add UniqueFieldValidator Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment