Skip to content

Latest commit

 

History

History
executable file
·
49 lines (44 loc) · 1.06 KB

File metadata and controls

executable file
·
49 lines (44 loc) · 1.06 KB

3.4 Getters validation

If you have getters validation:

namespace Acme\DemoBundle\Entity;
class User
{
    // ...

    /**
     * @return bool
     *
     * @Assert\True(message="The password cannot match your first name")
     */
    public function isPasswordLegal()
    {
        return $this->firstName != $this->password;
    }
}

then you have to create a callback:

Then you have to implement it on the JS side:

$('form#user').jsFormValidator({
    callbacks: {
        'isPasswordLegal': function() {
            var firstName = $('#user_firstName').val();
            var password = $('#user_password').val();
            return firstName != password;
        }
    }
});

Pure Javascript:

var field = document.getElementById('user');
FpJsFormValidator.customize(field, {
    callbacks: {
        'isPasswordLegal': function() {
            var firstName = document.getElementById('user_firstName').value;
            var password = document.getElementById('user_password').value;
            return firstName != password;
        }
    }
});