Jump to content

Validate.js Postcode validation always fail. Countries is empty


venditdevs

Recommended Posts

Hi,

In validate.js there is this code:

function validate_field(that)
{
	if ($(that).hasClass('is_required') || $(that).val().length)
	{
		if ($(that).attr('data-validate') == 'isPostCode')
		{
			var selector = '#id_country';
			if ($(that).attr('name') == 'postcode_invoice')
				selector += '_invoice';

			var id_country = $(selector + ' option:selected').val();

			if (typeof(countriesNeedZipCode[id_country]) != 'undefined' && typeof(countries[id_country]) != 'undefined')
				var result = window['validate_'+$(that).attr('data-validate')]($(that).val(), countriesNeedZipCode[id_country], countries[id_country]['iso_code']);
		}
		else if($(that).attr('data-validate'))
			var result = window['validate_' + $(that).attr('data-validate')]($(that).val());

		if (result)
			$(that).parent().removeClass('form-error').addClass('form-ok');
		else
			$(that).parent().addClass('form-error').removeClass('form-ok');
	}
}

$(document).on('focusout', 'input.validate, textarea.validate', function() {
	validate_field(this);
});

But the validation fails on empty var 'countries' when you need to check on postcode/zipcode

If i do this:

$(document).on('focusout', 'input.validate, textarea.validate', function() {
        console.log(countries);
	validate_field(this);
});

It gives an empty array

If i do this:

$(document).ready(function(){
    console.log(countries);
    $(document).on('focusout', 'input.validate, textarea.validate', function() {
        console.log(countries);
	validate_field(this);
    });
});

It gives me 1 filled array(the first) and 1 empty (the second)

If i set a console.log to output 'countries' in the validate_field function it also logs an empty array.

Seems to be failing on all our Prestashop installations ( with various different templates )

Any help/fix would be appreciated.

Link to comment
Share on other sites

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...