[html-formfu] Validate DBIx::Class unique constraints

Carl Franks fireartist at gmail.com
Mon Dec 6 10:58:32 GMT 2010


On 6 December 2010 10:47, Erez Schatz <moonbuzz at gmail.com> wrote:
> On 12/03/2010 01:35 PM, Carl Franks wrote:
>
>> There's also a HTML::FormFu::Constraint::DBIC::Unique
>
> Thanks, its a good solution, however...
>
>> I'm not sure what you mean by "this doesn't work if the user enters
>> his own information", can you give an example?
>
> When a user profile page loads, it is populated with current
> information. If a user clicks on "submit" it then submit all information
> that is in the form. Any "Unique" test will fail, seeing as the
> information is already in the DB - under the user's name!
>
> Is there a way to tell HTML::FF "validate only values that have been
> changed"?

Ah, I getcha.
I think the solution here would be to use different forms for the "add
profile" and the "edit profile" functions.
The first has the Unique constraint, the second doesn't.

An easy way to reuse the same basic form, if the only difference is
the constraint, would be something like this:

edit.yml
===
elements:
    - name: username


add.yml
===
load_config_file: 'edit.yml'
constraints:
    - type: 'DBIC::Unique'
      name: username

Will this work for you?
Carl



More information about the HTML-FormFu mailing list