2

In the login.phtml, what is the difference between validator and validate - Could someone explain what is the meaning of each of the lines below.

function onepageLogin(button)
        {
            if(loginForm.validator && loginForm.validator.validate()){
                button.disabled = true;
                loginForm.submit();
            }
        }

Thanks.

1 Answer 1

5

Take a look at js/prototype/validation.js

.....
onSubmit :  function(ev){
    if(!this.validate()) Event.stop(ev);
},
validate : function() {
    var result = false;
    var useTitles = this.options.useTitles;
    var callback = this.options.onElementValidate;
...

Then take a look at js/mage/adminhtml/form.js or (/js/varien/form.js)

varienForm.prototype = {
    initialize : function(formId, validationUrl){
        this.formId = formId;
        this.validationUrl = validationUrl;
        this.submitUrl = false;

        if($(this.formId)){
            this.validator  = new Validation(this.formId, {onElementValidate : this.checkErrors.bind(this)});
        }
        this.errorSections = $H({});
    },

then

var loginForm = new VarienForm('loginForm', false);

validator is a variable (see this.validator = new Validation..) that store the validation instance.

function onepageLogin(button)
{
    //check to see if the validator instance exist and programmatically validate the form
    if(loginForm.validator && loginForm.validator.validate()){  
        //disable the button to prevent multiple click             
        button.disabled = true;
        //submit the form since all the required field are entered 
        loginForm.submit();
    }
}

See Invoke validation

4
  • Very clear answer and good references. Is there a way that i can disable only password validation (while keeping the email validation intact) inside a form containing email and password
    – Vinu D
    Commented Jul 15, 2015 at 20:13
  • Remove the class name from password field Commented Jul 15, 2015 at 20:16
  • Thanks. i did exactly that. But on eventual submit, it still asks for the login and password. Is creating a dummy form and over-riding the only possible way around this
    – Vinu D
    Commented Jul 15, 2015 at 20:25
  • Turn on template hint or view page source to make sure you editing the correct file, all you need to do is remove the correct css classname Commented Jul 15, 2015 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.