Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated field is checked even if the main field is blank #10

Closed
BboyKeen opened this issue Jun 12, 2015 · 4 comments
Closed

Repeated field is checked even if the main field is blank #10

BboyKeen opened this issue Jun 12, 2015 · 4 comments

Comments

@BboyKeen
Copy link

Hi

I'm currently testing your bundle in my application.
I have a strange behaviour with a blank repeated field.

Here is the code to build my form

public function buildForm(FormBuilderInterface $builder, array $options)
{
        $builder
            ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
            ->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
            ->add('plainPassword', 'repeated', array(
                'type' => 'password',
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => 'form.password'),
                'second_options' => array('label' => 'form.password_confirmation'),
                'invalid_message' => 'fos_user.password.mismatch',
                'first_name' => 'password',
                'second_name' => 'password_repeated'
            ))
        ;
}

When I try to validate my form with client-side validation disabled, I got
form_server

And with client-side validation enabled :
form_client

I understand Symfony doesn't check the repeated field if the main field is blank whereas JQuery does.
Do you know how I can get the same result as Symfony ? Or even having the field considered as not correct.

By the way, I really like this bundle for saving me a lot of time.

Thanks

@BboyKeen BboyKeen changed the title Repeated field is not checked Repeated field is checked even if the main field is incorrect Jun 12, 2015
@BboyKeen BboyKeen changed the title Repeated field is checked even if the main field is incorrect Repeated field is checked even if the main field is blank Jun 12, 2015
@boekkooi
Copy link
Owner

Hi @BboyKeen,
Nice catch it seems that the equalTo is validating correct (since it is).

A quick way to fix this problem should be to use the constraints option in second_options.

    'second_options' => array(
        'label' => 'form.password_confirmation'
        'constraints' => array( new \Symfony\Component\Validator\Constraints\NotBlank() )
    ),

The actual problem here is more within jQueryValidate then within the bundle but it's confusing for sure. I will take a look at this once i have some spare time.
Ok this is a bug well spotted!

@BboyKeen
Copy link
Author

Hi @boekkooi,
Thanks for your quick answer.
I was pretty sure jQuery validation was the reason but I preferred to ask.
I just tried what you suggest and it's fully working, so thanks again ;)

@boekkooi
Copy link
Owner

@BboyKeen If you don't mind using the latest dev-master then you won't need the quickfix any more.

@BboyKeen
Copy link
Author

That sounds perfect. I will update immediately. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants