0

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))) {
    val1.classList.remove("validate-digits");
    val2.classList.remove("validate-digits");

  } else {
    val1.classList.add("validate-digits");
    val2.classList.add("validate-digits");
  }
Validation.validate($('street_1'));
Validation.validate($('street_2'));
}

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)

EDIT

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...

  • 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.