Jean Ter
Jean Ter

Reputation: 187

Symfony2 : Hide form field with display:none

I have a serious problem about symfony2 forms, the issue that I created a very long form,so I build it with parts(fields),so In the same form sometime I sumbit this part(fields) and I hide another using display:none and javascript code:

$('#{{form.price.vars.id}}').live('change', function(){
if ( $(this).is(':checked') ) {
 $('#action_{{form.price.vars.id}}').show();
} else {
 $('#action_{{form.price.vars.id}}').hide();
}
});

....

    <ul id="action_{{form.price.vars.id}}" style="display:none">
<li>{{ form_row(form.price_value)  }}</li>
<li>{{ form_row(form.price_subscription)  }}{{form_row(form.price_subscription_unit)}}</li>
<li>{{ form_row(form.price_activation)  }}{{form_row(form.price_activation_unit)}}</li>
</ul>
...

So when I hide this fields and I click submit the form still give me that this hidden fields are empty and I must enter a value,that is means the part is hide in the client side(html code) but in backend side he still not hide?

after submitting and when I show hidden fields to see what happend I have a notification "please enter a value in emply field"?

Upvotes: 1

Views: 2088

Answers (1)

Mick
Mick

Reputation: 31949

You need to use validation groups for this.

Nothing better than a Richard Miller post: Symfony2: Using Validation Groups. Take a particular look at Multiple Forms with one Entity.

Upvotes: 1

Related Questions