Try adding "groups="Edit" to the html field's NotBlank assertion params.
Leave the other assertions alone.

You'll need to instantiate two different forms for both the add and edit
actions. For add, you can create the form as you were before, as it will
validate against the "Default" group (implied for assertions that don't
specify "groups").  For the edit form, you can use a "validation_groups"
option of:

array('Default', 'Edit')

...which will include all assertions in the form's validation.  One caveat
is that if the form only has an html field, possible errors on
title/author_name/author_email would bubble up to the form object since the
fields don't exist. So it's good to display errors of the form itself (not
just its fields) in your template in order to catch this.  In practice, this
shouldn't ever happen if you rely on the add action and its validation to
create the object.

You could certainly limit the edit form to just use the "Edit" validation
group, but I like over-validating so I can catch invalid fields in the DB :)


On Thu, May 5, 2011 at 8:05 AM, Ruudk <[email protected]> wrote:

> I have a question about the validator component.
>
> My entity has the following properties:
>
>    - title (@assert:NotBlank)
>    - author_name (@assert:NotBlank)
>    - author_email (@assert:NotBlank @assert:Email)
>    - html (@assert:NotBlank)
>
> My "Add template" form has the following fields:
>
>    - title
>    - author_name
>    - author_email
>
> My "Edit html template" form has the following field:
>
>    - html
>
> The problem is that when I am adding a new template the html property is
> blank so validation will fail.
> How do I prevent this? In other words: how do I exclude the validation of
> the HTML property on the "Add template" page?
> When I am editing the template I only want to validate the html property.
> So then it cannot be blank.
>
> Hope someone can help me out.
>
>
>
>  --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>



-- 
jeremy mikola

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to