1

I would like to do a blur check on the contact form, but it only does the validation on the submit, I would like to know how I make this change.

I'm trying like this

    $j('contactForm').blur(function () {
          if (contactForm.validator.validate()) {
              alert('ok');
          } else {
              alert('no')
          }
     });

But I think I'd have to change the natural code for magento, right?

VarienForm = Class.create();
VarienForm.prototype = {
    initialize: function(formId, firstFieldFocus){
        this.form       = $(formId);
        if (!this.form) {
            return;
        }
        this.cache      = $A();
        this.currLoader = false;
        this.currDataIndex = false;
        this.validator  = new Validation(this.form);
        this.elementFocus   = this.elementOnFocus.bindAsEventListener(this);
        this.elementBlur    = this.elementOnBlur.bindAsEventListener(this);
        this.childLoader    = this.onChangeChildLoad.bindAsEventListener(this);
        this.highlightClass = 'highlight';
        this.extraChildParams = '';
        this.firstFieldFocus= firstFieldFocus || false;
        this.bindElements();
        if(this.firstFieldFocus){
            try{
                Form.Element.focus(Form.findFirstElement(this.form))
            }
            catch(e){}
        }
    },

    submit : function(url){
        if(this.validator && this.validator.validate()){
             this.form.submit();
        }
        return false;
    },
    ...
} 
0

Find the contact form phml file and add your script there.

Add it as

<script>
require([
    'jquery'
], function ($) {
    $(function () { // to ensure that code evaluates on page load

    $j('contactForm').blur(function () {
      if (contactForm.validator.validate()) {
        alert('ok');
      } else {
       alert('no')
      }
    });


  });
});
</script>
  • This is what I did, I would like to do the fields validation in the blur, but it already has a validation done, only that is only in the submit, I would like to change it and put it in the blur .. – Gustavo Souza Sep 25 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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