I am validating my address fields for numbers.
In some countries house number is mandatory to make the delivery.

Since I don't care which field the number is written in, I want the validation to be stopped for both fields if one of the fields contains a number.

I came up with this:

var digvalenable = function(){
  var val1 = document.getElementById('street_1');
  var val2 = document.getElementById('street_2');

  if ((/\d/.test(val1.value))  || (/\d/.test(val2.value))) {

  } else {

Which basically adds the validation class if a number is not present and removes it if there is a number.

It works great, except the message for my number validation does not disappear (I can save the value- validation-passed)


Currently I am solving this by:

document.getElementById('advice-validate-digits-street_1').style = "display:none";

But this does not have the fade out effect...

| improve this question | | | | |
  • What is it what are tyring to achieve exactly? Just a fade out on the validation message? – Akif Aug 23 '17 at 12:46
  • I thought that it would fade out and disappear automatically like it does with Magento usually, but for whatever reason it is not happening. I am trying to find a reason why. – Jurģis Toms Liepiņš Aug 23 '17 at 14:56
  • Nothing happens by itself unless you tell something to do so :) Two question to help you further. Do you have jQuery available on the specific page? And on which event do you want to do the fade out of the validation message? – Akif Aug 23 '17 at 21:16
  • Don't get me wrong, I am no stranger to this. But I thought since I remove the validation class from input tag and then validate the field, it should update and fade out the message as it normally does – Jurģis Toms Liepiņš Aug 24 '17 at 9:57
  • Currently I am just using only prototype js, but so far it has been sufficient. Well, as I said, I thought the fade out would happen as I update the validation. – Jurģis Toms Liepiņš Aug 24 '17 at 11:07

Your Answer

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

Browse other questions tagged or ask your own question.