Open jbustamanterendon opened 8 years ago
Yes, that sounds reasonable.
The concept behind the "eventContext" was not really thought through when introduced, but since it has stayed around for some time now it probably exists for a good reason.
Hello,
In our case it is necessary to know if it was launched by "Blur" or "Submit", based on this we take different decisions.
check this code:
$.formUtils.addValidator({
name: 'isVatNumber',
validatorFunction: function (value, $el, config, language, $form, eventContext) {
var result = true;
var data = {
url_call: orderOpcUrl + '?rand=' + new Date().getTime(),
is_ajax: true,
async: false,
action: 'checkVATNumber',
vat_number: value
};
//if (!$.isEmpty(value)){
var _json = {
data: data,
beforeSend: function(){
$('div#onepagecheckoutps #onepagecheckoutps_step_one_container .loading_small').show();
},
success: function(data) {
$('div#onepagecheckoutps #onepagecheckoutps_step_one_container .loading_small').hide();
if (!$.isEmpty(data[0])){
Fronted.showModal({type:'error', message : data[0]});
result = false;
} else {
if (eventContext == 'blur') {
Carrier.getByCountry();
}
}
}
};
$.makeRequest(_json);
//}
return result;
},
validateOnKeyUp: false,
errorMessage: 'This is not a valid.',
errorMessageKey: 'errorGlobal'});
Best regards.
But your code doesn't make sense to me. Isn't $.makeRequest
asynchronous? That means that this validator will always return result = true
.
The validatorFunction
does not support async behaviour.
I just like to show you this:
if (eventContext == 'blur') {
Carrier.getByCountry();
}
On my validations custom fields, need the "eventContext" :)
Fixed!
Great!! very thanks!. This plugins is the better !! We use it in our project module for PrestaShop http://www.presteamshop.com/en/modules-prestashop/one-page-checkout-prestashop.html
We'll have it open until stable version the plugin is released
Hello,
We need a new feature on the "validatorFunction" need to receive the "eventContext" as the last parameter, thank you.
Best regards.