Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Ceformvalidator Problem With Ajax Rate Topic   - - - - -

 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 395 posts

Posted 08 January 2019 - 01:42 PM #1

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 ?



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18922 posts

Posted 08 January 2019 - 01:45 PM #2

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 395 posts

Posted 08 January 2019 - 02:17 PM #3

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



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11198 posts

Posted 08 January 2019 - 06:54 PM #4

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


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3269 posts

Posted 09 January 2019 - 05:30 AM #5

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


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18922 posts

Posted 09 January 2019 - 06:29 AM #6

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 395 posts

Posted 09 January 2019 - 06:44 AM #7

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 ?



 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3269 posts

Posted 10 January 2019 - 05:27 AM #8

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?


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18922 posts

Posted 10 January 2019 - 05:38 AM #9

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 395 posts

Posted 10 January 2019 - 09:38 AM #10

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