1

I have a form, with the following div created when there is an error on the email field when we submit the form. Meaning the div doesn't exist is the original form.

<div for="email_rappel" generated="true" class="mage-error" id="email_rappel-error">
'Please enter a valid email address.'</div>

I would like to make an event when the div is created..in order to do that, I've tried the following; but seems like nothing is triggered the log never happens and can't tell why.

        var emailError = jQuery('#email_rappel-error');
        emailError.bind('DOMNodeInserted DOMSubtreeModified DOMNodeRemoved', function(event) {
            console.log("test");
            if(emailError.text() === "'Please enter a valid email address.'"){
                //do something
            }
        });

Any suggestion ?

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Claims
  • 245
  • 2
  • 15
  • What version of jQuery are you using? `.bind()` has been deprecated for many years – j08691 Nov 09 '21 at 16:43
  • @j08691 I'm not familiar with jQuery i indeed found this on a very old stack topic...but none were "up do date" with this problematic. I think I'm using : jQuery JavaScript Library v1.12.4 – Claims Nov 09 '21 at 16:48
  • 1
    However, I would suggest this is not your best solution. Given the class `mage-error` I would guess this is a magento site, so you might be better off asking on [magento.stackexchange.com/](https://magento.stackexchange.com/) how to hook into form validation correctly (though I don't know if that *is* an appropriate site and they may just send you back here for coding questions ...) – freedomn-m Nov 09 '21 at 17:11
  • @freedomn-m Indeed, thing is i already handled the translation properly the magento way...but this one won't do...thats why I was trying to find a workaround. I will check your link : EDIT : Looks like this is what i'm looking for but i'm not sure to understand how to set this up properly – Claims Nov 09 '21 at 18:30
  • 1
    @freedomn-m I ended up with a different kind of work around...I've checked the validity by regex on the email input and disabled the form submit while the form isn't fine. It's not perfect as it will still be possible to enable the submit from editing sources...but it will do the job. Thanks for assist ! – Claims Nov 10 '21 at 09:34
  • Glad you got a working solutions. Thanks for the feedback. – freedomn-m Nov 10 '21 at 10:01

0 Answers0