Ceformvalidator Problem With Ajax

hi i am validating a filed with ce.ajax function everything working well with console.

but

$.ceFormValidator('registerValidator', {

dont wait fnish the validation for return true; getting automatically false.

what can i do ?

Please provide us with more details how do you use this code

$.ceFormValidator('registerValidator', {
                class_name: 'x_field',
                message: 'error_xfield',
                func: function(id) {
                    var input = $('#' + id);
                        $.ceAjax('request', fn_url('location.check_x'), {
                            method: 'post',
                            caching: false,
                            data: {x_field: input.val()},
                            callback: function (response) {
                                data = JSON.parse(response.result);
                                if (data == true) {
                                    console.log('x true');
                                    return true;
                                } else {
                                    console.log('x false');
                                    return false;
                                }
                            }
                        });

                }
            });

here is the code. all console logs its correct but registerValidator doesnt wait ceAjax result ? how can i fix that ?

What is the html where you are expecting your validator to engage?

$.ceFormValidator('registerValidator', {
                class_name: 'x_field',
                message: 'error_xfield',
                func: function(id) {
                    var input = $('#' + id);
                        $.ceAjax('request', fn_url('location.check_x'), {
                            method: 'post',
                            caching: false,
                            data: {x_field: input.val()},
                            callback: function (response) {
                                data = JSON.parse(response.result);
                                if (data == true) {
                                    console.log('x true');
                                    return true;
                                } else {
                                    console.log('x false');
                                    return false;
                                }
                            }
                        });
            }
        });

here is the code. all console logs its correct but registerValidator doesnt wait ceAjax result ? how can i fix that ?

Hello,

Try to do it another way - make field validation ($.ceFormValidator) in ajax callback.

Right, it will not work in such a way with asynchronous requests

Ok new code here; but doesnt work first click, working with second click

 $(document).ready(function () {
               $('form button[type=submit]').on('click', function (e) {
                var input = $('#elm_38');
                $.ceAjax('request', fn_url('location.check_x'), {
                    method: 'post',
                    caching: false,
                    data: {x_field: input.val()},
                    callback: function (response) {
                        data = JSON.parse(response.result);
                    $.ceFormValidator('registerValidator', {
                        class_name: 'x_field',
                        message: 'error_xfield',
                        func: function(id) {

                            if(data == true) {
                                console.log('x true');
                                return true;

                            }else{
                                console.log('x false');
                                return false;
                            }
                        }
                    });
                }
            });
        });
    });

what missing ?

Ok new code here; but doesnt work first click, working with second click

 $(document).ready(function () {
               $('form button[type=submit]').on('click', function (e) {
                var input = $('#elm_38');
                $.ceAjax('request', fn_url('location.check_x'), {
                    method: 'post',
                    caching: false,
                    data: {x_field: input.val()},
                    callback: function (response) {
                        data = JSON.parse(response.result);
                    $.ceFormValidator('registerValidator', {
                        class_name: 'x_field',
                        message: 'error_xfield',
                        func: function(id) {

                            if(data == true) {
                                console.log('x true');
                                return true;

                            }else{
                                console.log('x false');
                                return false;
                            }
                        }
                    });
                }
            });
        });
    });

what missing ?

What do you check in location.check_x? Can it be done in js?

I do not think that it will work in this way since ajax in CS-Cart does not use the async parameter (it is always set to true) and it is not possible to make synchronous requests

its work on input blur event now. i iwll use this way until found another solution. thank you all