jQWidgets Forums

jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable how to check input validation with ajax?

This topic contains 2 replies, has 2 voices, and was last updated by  snowyl 11 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • snowyl
    Member

    I want use ajax to check the input company name’s validation. The code is :
    $(‘#CompanyForm’).jqxValidator({
    rules: [
    { input: ‘#companyname’, message: ‘Company name is required!’, action:’blur’, rule: ‘required’ },
    { input: ‘#companyname’, message: ‘Company name is used!’, action:’blur’,
    rule: function (input, commit) {
    var companydata={};
    companydata[“name”]=input.val();
    if(companydata[“name”]==””)
    return false;
    //—————–begin——————————
    $.ajax({
    cache: false,
    dataType: ‘json’,
    url: ‘ajax/company.ashx?action=checkcomapny&ts=’+new Date(),
    data: companydata,
    type: “GET”,
    success: function (data, status, xhr) {
    if (data==”ok”)
    {
    commit(true);
    }
    else
    {
    commit(false);
    }
    },
    error: function (jqXHR, textStatus, errorThrown) {
    commit(false);
    }
    });
    //————————————–end————————-
    }
    }
    ], theme: theme
    });
    $(‘#sendButton’).click(function () {
    if( $(‘#CompanyForm’).jqxValidator(‘validate’))
    alert();
    });

    The validation can works. But when the button is clicked, $(‘#CompanyForm’).jqxValidator(‘validate’) always is undefinded even though the comany name is ok.
    If I delete the ajax code (from –begin– to the –end–)and return true or false, I can get the $(‘#CompanyForm’).jqxValidator(‘validate’) when I click the button.

    I don’t know how to submit after validate.


    support
    Participant

    Hi snowyl,

    If you want to submit after validate you can by using ‘validate’ function as shown:

    $('#testForm').jqxValidator('validate', function (result) {
    alert(result);
    }
    );

    Best Wishes,
    Mariya

    jQWidgets Team
    http://www.jqwidgets.com


    snowyl
    Member

    Thank you.
    I tried to use
    $(‘#CompanyForm’).jqxValidator(‘validate’, function (result) {
    alert(result);
    } );
    The problem still exists. if I do not use ajax to check the company name. It is ok. Only if I add ajax function, when I input everything needed,the ‘validate’ function does not executed. Is anything wrong with my ajax function. By the way, the check of company name works properly. But seems no signal send back to call the ‘validate’. If I change the ‘commit(true)’ to ‘return true’, the check company name won’t work.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.