Symfony sfValidators:动态设置值是否需要?

I have the following problem:

I have a form where a user can opt to toggle a switch (Yes/No).

If they select Yes, I hide a couple of fields on my template (because they will now automatically be calculated).

The catch is that now, a set of different fields are required to not be empty for the successful submission.

The first fields need not be optional after the switch is clicked (since they are merely hidden but still submitted), but the second set of fields must be non-empty.

Is there a simple way to get this dynamic validation behaviour using Symfony's sfValidator classes, or should I simply hack together a solution using jQuery?

This sounds like a perfect case for the Callback constraint that already exists in Symfony. To quote the linked doc:

The purpose of the Callback constraint is to create completely custom validation rules and to assign any validation errors to specific fields on your object. If you're using validation with forms, this means that you can make these custom errors display next to a specific field, instead of simply at the top of your form.

This solves the backend, you still need to watch out for the required attributes of your fields so HTML5 validation can work properly.