jQWidgets Forums

Forum Replies Created

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • in reply to: ajax validation problem ajax validation problem #71810

    brio
    Participant

    Dear Peter,
    I look at that demo many and many times.
    On my code ajax validations work fine but validationSuccess event doesn’t start.
    I really don’t know what to do 🙁
    Have you got some suggests more, please?

    in reply to: ajax validation problem ajax validation problem #71672

    brio
    Participant

    dear Peter,
    it’s me again; still with this problem.
    ‘validationSuccess’ works only when I cut off ajax rule.
    Php rule works fine, I think.
    I would like to show you some code abstract.

    $('#registrationForm').jqxValidator({
                        hintType: 'label',
                        rules: [
                            {input: '#nome', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#nome', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'},
                            {input: '#cognome', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#cognome', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'},
                            {input: '#codicefiscale', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#codicefiscale', message: 'codice fiscale non valido.', action: 'blur', rule: function (input, commit) {
                                    var cf = $('#codicefiscale').val(), validi, i, s, set1, set2, setpari, setdisp;
                                    if (cf == '')
                                        return '';
                                    cf = cf.toUpperCase();
                                    if (cf.length != 16)
                                        return false;
                                    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                                    for (i = 0; i < 16; i++) {
                                        if (validi.indexOf(cf.charAt(i)) == -1)
                                            return false;
                                    }
                                    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                                    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
                                    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                                    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
                                    s = 0;
                                    for (i = 1; i <= 13; i += 2)
                                        s += setpari.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
                                    for (i = 0; i <= 14; i += 2)
                                        s += setdisp.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
                                    if (s % 26 != cf.charCodeAt(15) - 'A'.charCodeAt(0))
                                        return false;
                                    return true;
                                }
                            },
                            {input: '#comune', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#comune', message: 'campo obbligatorio.', action: 'blur', rule: 'minLength=2'},
                            {input: '#indirizzo', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#indirizzo', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'},
                            {input: '#telefonofisso123', message: 'numero telefonico non valido.', action: 'blur', rule: function (input, commit) {
                                    var telefonofisso = $('#telefonofisso123').val();
                                    if (telefonofisso.length >= 7) {
                                        switch (telefonofisso.substr(0, 2)) {
                                            case "00":
                                                if (telefonofisso.substr(0, 3) == "004") { //004 è il prefisso di Campione d'Italia
                                                    return true;
                                                } else {
                                                    return false;
                                                }
                                                break;
                                            default:
                                                if (telefonofisso.substr(0, 1) == "0") {
                                                    return true;
                                                } else {
                                                    return false;
                                                }
                                                break;
                                        }
                                    } else if (telefonofisso.length == 0) {
                                        return true;
                                    } else {
                                        return false;
                                    }
                                    ;
                                }
                            },
                            {input: '#telefonocellulare123', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            //{input: '#telefonocellulare123', message: 'numero telefonico non valido.', action: 'blur', rule: 'minLength=9'},
                            {input: '#telefonocellulare123', message: 'numero telefonico non valido.', action: 'blur', rule: function (input, commit) {
                                    var telefonocellulare = $('#telefonocellulare123').jqxInput('val');
                                    if (telefonocellulare.length == 10) {
                                        $.ajax({
                                            type: 'POST',
                                            url: "valida_telefono_cellulare.php",
                                            //dataType: 'html',
                                            data: {telefono_cellulare: telefonocellulare},
                                            success: function (data)
                                            {
                                                if (data == "true")
                                                {
                                                    commit(true);
                                                }
                                                else commit(false);
                                            },
                                            error: function ()
                                            {
                                                commit(false);
                                            }
                                        });
                                    } else if (telefonocellulare.length == 0) {
                                        return true;
                                    } else {
                                        return false;
                                    }
                                }
                            },
                            {input: '#email', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#email', message: 'indirizzo email non valido.', action: 'blur', rule: function (input, commit) {
                                    var email = $('#email').jqxInput('val');
                                    $.ajax({
                                        type: 'POST',
                                        url: "valida_email.php",
                                        //dataType: 'html',
                                        data: {email: email},
                                        success: function (data)
                                        {
                                            if (data == "true")
                                            {
                                                commit(true);
                                            }
                                            else commit(false);
                                        },
                                        error: function ()
                                        {
                                            commit(false);
                                        }
                                    });
                                }
                            },
                            {input: '#password', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#password', message: 'la password dev\'essere compresa tra 6 e 12 caratteri.', action: 'blur', rule: 'length=6,12'},
                            {input: '#conferma_password', message: 'campo obbligatorio.', action: 'blur', rule: 'required'},
                            {input: '#conferma_password', message: 'non c\'è corrispondenza con la password.', action: 'blur', rule: function (input, commit) {
                                    // call commit with false, when you are doing server validation and you want to display a validation error on this field. 
                                    if (input.val() === $('#password').val()) {
                                        return true;
                                    }
                                    return false;
                                }}
                        ], theme: theme
                    });
    
                    $('#registrationForm').on('validationSuccess', function (event) {
    alert();
    //                    alert('You have filled the form correctly!')
    //                    $.post("registrazione.php", $("#registrationForm").serialize(), function(result) {
    //                        $("span").html(result);
    //                    });
    //                    $("span").html($("#registrationForm").serialize());
                        $.post("registrazione.php", {
                            nome: $('#nome').val(),
                            cognome: $('#cognome').val(),
                            codicefiscale: $('#codicefiscale').val(),
                            comune: $('#comune').val(),
                            indirizzo: $('#indirizzo').val(),
                            cap: $('#cap').val(),
                            telefonofisso: $('#telefonofisso123').val(),
                            telefonocellulare: $('#telefonocellulare123').val(),
                            email: $('#email').val(),
                            password: $('#password').val(),
                            ip: $('#ip').val()
                        }, function (result) {
                            $("#windowsMessage").html(result);
                            $('#eventWindow').jqxWindow('open');
                        });
                    });
                    $('#sendButton').jqxButton({width: 100, height: 25, theme: theme});
                    $("#sendButton").click(function () {
                        $('#registrationForm').jqxValidator('validate');
                    });
    <?php
    
    function disposablecheck($telefono_cellulare) {
        $whitelist = array(
            "313",
            "320",
            "322",
            "323",
            "324",
            "327",
            "328",
            "329",
            "330",
            "331",
            "334",
            "335",
            "336",
            "337",
            "338",
            "339",
            "340",
            "341",
            "342",
            "343",
            "345",
            "346",
            "347",
            "348",
            "349",
            "350",
            "351",
            "360",
            "361",
            "362",
            "363",
            "366",
            "368",
            "370",
            "373",
            "375",
            "377",
            "380",
            "383",
            "388",
            "389",
            "390",
            "391",
            "392",
            "393",
            "397"
        );
    
        $telefono_cellulare_prefisso = substr($telefono_cellulare, 0, 3);
    
        if (in_array($telefono_cellulare_prefisso, $whitelist)) {
            return 0;
        } else {
            return 1;
        }
    }
    
    $cellulare = $_POST["telefono_cellulare"];
    
    //if (disposablecheck($_POST["telefono_cellulare"]) == 1) {
    if (disposablecheck($cellulare) == 1) {
        //do stuff for disposable emails
        echo "false";
        return;
    } else {
        //do stuff if not disposable email
        echo "true";
        return;
    }
    ?>
    <?php
    
    function disposablecheck($email) {
        $blacklist = array(
            "0815.ru0clickemail.com",
            "0wnd.net",
            "0wnd.org",
            "10minutemail.com",
            "20minutemail.com",
            "2prong.com",
            "3d-painting.com",
            "4warding.com",
            "4warding.net",
            "4warding.org",
            "9ox.net",
            "a-bc.net",
            "amilegit.com",
            "anonbox.net",
            "anonymbox.com",
            "antichef.com",
            "antichef.net",
            "antispam.de",
            "baxomale.ht.cx",
            "beefmilk.com",
            "binkmail.com",
            "bio-muesli.net",
            "bobmail.info",
            "bodhi.lawlita.com",
            "bofthew.com",
            "brefmail.com",
            "bsnow.net",
            "bugmenot.com",
            "bumpymail.com",
            "casualdx.com",
            "chogmail.com",
            "cool.fr.nf",
            "correo.blogos.net",
            "cosmorph.com",
            "courriel.fr.nf",
            "courrieltemporaire.com",
            "curryworld.de",
            "cust.in",
            "dacoolest.com",
            "dandikmail.com",
            "deadaddress.com",
            "despam.it",
            "devnullmail.com",
            "dfgh.net",
            "digitalsanctuary.com",
            "discardmail.com",
            "discardmail.de",
            "disposableaddress.com",
            "disposemail.com",
            "dispostable.com",
            "dm.w3internet.co.uk example.com",
            "dodgeit.com",
            "dodgit.com",
            "dodgit.org",
            "dontreg.com",
            "dontsendmespam.de",
            "dump-email.info",
            "dumpyemail.com",
            "e4ward.com",
            "email60.com",
            "emailias.com",
            "emailinfive.com",
            "emailmiser.com",
            "emailtemporario.com.br",
            "emailwarden.com",
            "ephemail.net",
            "explodemail.com",
            "fakeinbox.com",
            "fakeinformation.com",
            "fastacura.com",
            "filzmail.com",
            "fizmail.com",
            "frapmail.com",
            "garliclife.com",
            "get1mail.com",
            "getonemail.com",
            "getonemail.net",
            "girlsundertheinfluence.com",
            "gishpuppy.com",
            "great-host.in",
            "gsrv.co.uk",
            "guerillamail.biz",
            "guerillamail.com",
            "guerillamail.net",
            "guerillamail.org",
            "guerrillamail.com",
            "guerrillamailblock.com",
            "haltospam.com",
            "hotpop.com",
            "ieatspam.eu",
            "ieatspam.info",
            "ihateyoualot.info",
            "imails.info",
            "inboxclean.com",
            "inboxclean.org",
            "incognitomail.com",
            "incognitomail.net",
            "ipoo.org",
            "irish2me.com",
            "jetable.com",
            "jetable.fr.nf",
            "jetable.net",
            "jetable.org",
            "junk1e.com",
            "kaspop.com",
            "kulturbetrieb.info",
            "kurzepost.de",
            "lifebyfood.com",
            "link2mail.net",
            "litedrop.com",
            "lookugly.com",
            "lopl.co.cc",
            "lr78.com",
            "maboard.com",
            "mail.by",
            "mail.mezimages.net",
            "mail4trash.com",
            "mailbidon.com",
            "mailcatch.com",
            "maileater.com",
            "mailexpire.com",
            "mailin8r.com",
            "mailinator.com",
            "mailinator.net",
            "mailinator2.com",
            "mailincubator.com",
            "mailme.lv",
            "mailnator.com",
            "mailnull.com",
            "mailzilla.org",
            "mbx.cc",
            "mega.zik.dj",
            "meltmail.com",
            "mierdamail.com",
            "mintemail.com",
            "moncourrier.fr.nf",
            "monemail.fr.nf",
            "monmail.fr.nf",
            "mt2009.com",
            "mx0.wwwnew.eu",
            "mycleaninbox.net",
            "mytrashmail.com",
            "neverbox.com",
            "nobulk.com",
            "noclickemail.com",
            "nogmailspam.info",
            "nomail.xl.cx",
            "nomail2me.com",
            "no-spam.ws",
            "nospam.ze.tc",
            "nospam4.us",
            "nospamfor.us",
            "nowmymail.com",
            "objectmail.com",
            "obobbo.com",
            "onewaymail.com",
            "ordinaryamerican.net",
            "owlpic.com",
            "pookmail.com",
            "proxymail.eu",
            "punkass.com",
            "putthisinyourspamdatabase.com",
            "quickinbox.com",
            "rcpt.at",
            "recode.me",
            "recursor.net",
            "regbypass.comsafe-mail.net",
            "safetymail.info",
            "sandelf.de",
            "saynotospams.com",
            "selfdestructingmail.com",
            "sendspamhere.com",
            "shiftmail.com",
            "****mail.me",
            "skeefmail.com",
            "slopsbox.com",
            "smellfear.com",
            "snakemail.com",
            "sneakemail.com",
            "sofort-mail.de",
            "sogetthis.com",
            "soodonims.com",
            "spam.la",
            "spamavert.com",
            "spambob.net",
            "spambob.org",
            "spambog.com",
            "spambog.de",
            "spambog.ru",
            "spambox.info",
            "spambox.us",
            "spamcannon.com",
            "spamcannon.net",
            "spamcero.com",
            "spamcorptastic.com",
            "spamcowboy.com",
            "spamcowboy.net",
            "spamcowboy.org",
            "spamday.com",
            "spamex.com",
            "spamfree24.com",
            "spamfree24.de",
            "spamfree24.eu",
            "spamfree24.info",
            "spamfree24.net",
            "spamfree24.org",
            "spamgourmet.com",
            "spamgourmet.net",
            "spamgourmet.org",
            "spamherelots.com",
            "spamhereplease.com",
            "spamhole.com",
            "spamify.com",
            "spaminator.de",
            "spamkill.info",
            "spaml.com",
            "spaml.de",
            "spammotel.com",
            "spamobox.com",
            "spamspot.com",
            "spamthis.co.uk",
            "spamthisplease.com",
            "speed.1s.fr",
            "suremail.info",
            "tempalias.com",
            "tempemail.biz",
            "tempemail.com",
            "tempe-mail.com",
            "tempemail.net",
            "tempinbox.co.uk",
            "tempinbox.com",
            "tempomail.fr",
            "temporaryemail.net",
            "temporaryinbox.com",
            "thankyou2010.com",
            "thisisnotmyrealemail.com",
            "throwawayemailaddress.com",
            "tilien.com",
            "tmailinator.com",
            "tradermail.info",
            "trash2009.com",
            "trash-amil.com",
            "trashmail.at",
            "trash-mail.at",
            "trashmail.com",
            "trash-mail.com",
            "trash-mail.de",
            "trashmail.me",
            "trashmail.net",
            "trashymail.com",
            "trashymail.net",
            "tyldd.com",
            "uggsrock.com",
            "wegwerfmail.de",
            "wegwerfmail.net",
            "wegwerfmail.org",
            "wh4f.org",
            "whyspam.me",
            "willselfdestruct.com",
            "winemaven.info",
            "wronghead.com",
            "wuzupmail.net",
            "xoxy.net",
            "yogamaven.com",
            "yopmail.com",
            "yopmail.fr",
            "yopmail.net",
            "yuurok.com",
            "zippymail.info",
            "jnxjn.com",
            "trashmailer.com",
            "klzlk.com",
        );
    
        $email_split = explode('@', $email);
        $email_domain = $email_split[1];
    
        if (in_array($email_domain, $blacklist)) {
            //Return 1, disposable email detected
            return 1;
        } else {
            //Return 0, no match found
            return 0;
        }
    }
    
    $email = $_POST["email"];
    
    if (validEmail($email) == true) {
        if (disposablecheck($email) == 1) {
            //do stuff for disposable emails
            echo "false";
        } else {
            //do stuff if not disposable email
            echo "true";
        };
        return;
    } else {
        echo "false";
        return;
    };
    
    function validEmail($email) {
        $isValid = true;
        $atIndex = strrpos($email, "@");
        if (is_bool($atIndex) && !$atIndex) {
            $isValid = false;
        } else {
            $domain = substr($email, $atIndex + 1);
            $local = substr($email, 0, $atIndex);
            $localLen = strlen($local);
            $domainLen = strlen($domain);
            if ($localLen < 1 || $localLen > 64) {
                // local part length exceeded
                $isValid = false;
            } else if ($domainLen < 1 || $domainLen > 255) {
                // domain part length exceeded
                $isValid = false;
            } else if ($local[0] == '.' || $local[$localLen - 1] == '.') {
                // local part starts or ends with '.'
                $isValid = false;
            } else if (preg_match('/\\.\\./', $local)) {
                // local part has two consecutive dots
                $isValid = false;
            } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
                // character not valid in domain part
                $isValid = false;
            } else if (preg_match('/\\.\\./', $domain)) {
                // domain part has two consecutive dots
                $isValid = false;
            } else if
            (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) {
                // character not valid in local part unless 
                // local part is quoted
                if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) {
                    $isValid = false;
                }
            }
            if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) {
                // domain not found in DNS
                $isValid = false;
          }
       }
       return $isValid;
    }
    
    ?>

    Any suggest?
    Thanks and best regards
    Brio

    in reply to: ajax validation problem ajax validation problem #47108

    brio
    Participant

    Hi Peter,
    thanks for answering.
    I checked everything (I think) in my code, that’s similar to your example.
    When validation fails, a red pop up informs me.
    I tried even the opposite validation answer “validationError” (*).
    In both case alert() doesn’t start.

    best regard,
    Brio

    *)

    $('#testForm').on('validationSuccess', function(event) {
                        alert('You have filled the form correctly!')
                    });
    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #28279

    brio
    Participant

    better code.
    bye

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <link rel="stylesheet" href="jqwidgets/styles/jqx.classic.css" type="text/css" />
    <script type="text/javascript" src="scripts/gettheme.js"></script>
    <script type="text/javascript" src="scripts/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.maskedinput.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxexpander.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxnumberinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxvalidator.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var theme = getDemoTheme();
    var firstItem = new Object();
    $("#jqxinput").jqxInput(
    {
    theme: theme,
    width: 200,
    height: 25,
    minLength: 2,
    source: function(query, response) {
    var dataAdapter = new $.jqx.dataAdapter
    (
    {
    datatype: "json",
    datafields: [{name: 'comune', type: 'string'}],
    url: 'data.php'
    },
    {
    autoBind: true,
    formatData: function(data) {
    data.query = query;
    return data;
    },
    loadComplete: function(data) {
    firstItem = data[0];
    if (data.length > 0) {
    response($.map(data, function(item) {
    return item.comune;
    }));
    }
    ;
    }
    }
    );
    }
    });
    $("#jqxinput").on("blur", function() {
    var placeHolder = $('#jqxinput').jqxInput("placeHolder");
    var value = $('#jqxinput').jqxInput('val');
    if (value == "" || value == placeHolder) {
    return;
    } else {
    if (firstItem) {
    var label = firstItem.comune;
    if (value.length > label.length) {
    $('#jqxinput').jqxInput('val', "");
    } else {
    if (label.toLowerCase().substr(0, value.length) == value.toLowerCase()) {
    $('#jqxinput').jqxInput('val', label);
    }
    else {
    $('#jqxinput').jqxInput('val', "");
    }
    }
    }
    ;
    }
    ;
    });
    });
    </script>
    <style type="text/css">
    .text-input
    {
    height: 21px;
    width: 150px;
    }
    .register-table
    {
    margin-top: 10px;
    margin-bottom: 10px;
    }
    .register-table td, .register-table tr
    {
    margin: 0px;
    padding: 2px;
    border-spacing: 0px;
    border-collapse: collapse;
    font-family: Verdana;
    font-size: 12px;
    }
    h3
    {
    display: inline-block;
    margin: 0px;
    }
    </style>
    </head>
    <body class='default'>
    <div id="register">
    <div>
    <h3>
    Registrazione</h3>
    </div>
    <div>
    <form id="testForm" action="./">
    <table class="register-table">
    <tr>
    <td>
    comune di residenza:
    </td>
    <td>
    <input id="jqxinput" />
    </td>
    </tr>
    </table>
    </form>
    </div>
    </div>
    </body>
    </html>
    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #28235

    brio
    Participant

    Hi Dimitar,

    that’s the right example!
    I was very very near to this solution.
    But probably I couldn’t solve the matter alone.
    Thanks alot.
    Francesco

    p.s.: I paste my code for everybody.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <link rel="stylesheet" href="jqwidgets/styles/jqx.classic.css" type="text/css" />
    <script type="text/javascript" src="scripts/gettheme.js"></script>
    <script type="text/javascript" src="scripts/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.maskedinput.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxexpander.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxnumberinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxvalidator.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var theme = getDemoTheme();
    var firstItem = new Object();
    $("#jqxinput").jqxInput(
    {
    theme: theme,
    width: 200,
    height: 25,
    minLength: 2,
    source: function(query, response) {
    var dataAdapter = new $.jqx.dataAdapter
    (
    {
    datatype: "json",
    datafields: [{name: 'comune', type: 'string'}],
    url: 'data.php'
    },
    {
    autoBind: true,
    formatData: function(data) {
    data.query = query;
    return data;
    },
    loadComplete: function(data) {
    firstItem = data[0];
    if (data.length > 0) {
    response($.map(data, function(item) {
    return item.comune;
    }));
    }
    ;
    }
    }
    );
    }
    });
    $("#jqxinput").on("blur", function () {
    var placeHolder = $('#jqxinput').jqxInput("placeHolder");
    var value = $('#jqxinput').jqxInput('val');
    if (value == "" || value == placeHolder) {
    return;
    } else {
    if (firstItem) {
    var label = firstItem.comune;
    $('#jqxinput').jqxInput('val', label);
    };
    };
    });
    });
    </script>
    <style type="text/css">
    .text-input
    {
    height: 21px;
    width: 150px;
    }
    .register-table
    {
    margin-top: 10px;
    margin-bottom: 10px;
    }
    .register-table td, .register-table tr
    {
    margin: 0px;
    padding: 2px;
    border-spacing: 0px;
    border-collapse: collapse;
    font-family: Verdana;
    font-size: 12px;
    }
    h3
    {
    display: inline-block;
    margin: 0px;
    }
    </style>
    </head>
    <body class='default'>
    <div id="register">
    <div>
    <h3>
    Registrazione</h3>
    </div>
    <div>
    <form id="testForm" action="./">
    <table class="register-table">
    <tr>
    <td>
    comune di residenza:
    </td>
    <td>
    <input id="jqxinput" />
    </td>
    </tr>
    </table>
    </form>
    </div>
    </div>
    </body>
    </html>
    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #28184

    brio
    Participant

    Hi Dimitar,
    this example forgets ‘query’ and ‘response’ parameters, still included in dataFormat and loadComplete.
    I think ‘query’ could be replaced by ‘$(‘#jqxinput’).jqxInput(‘val’);’.
    and ‘response’?
    Do you think I have not solved the problem by a long way?
    Thanks
    Francesco

    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #28119

    brio
    Participant

    Hi Dimitar,

    I dont’ know how to make sourceFuntion returning an array of values.
    I tried few solutions and I failured.

    data.php returns json_encode($comuni).
    for example [{“comune”:”Abano Terme”},{“comune”:”Abbadia Cerreto”},{“comune”:”Abbadia Lariana”},{“comune”:”Abbadia San Salvatore”},{“comune”:”Abbasanta”},{“comune”:”Abbateggio”},{“comune”:”Abbiategrasso”},{“comune”:”Abetone”},{“comune”:”Abriola”},{“comune”:”Acate”}]

    do I have to change data.php or just loadComplete in function (query, response)?

    I think I can’t solve it by myself.

    Best regards.
    Francesco

    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #27863

    brio
    Participant

    Hi Dimitar,
    I changed “var source = sourceFuntion(query, response);” in “var source = sourceFuntion;” (did I mistake?).
    now it finds items on typing, but blur event is stil not working.
    I think “source” is null inside blur event.
    I’m sorry to keep on asking help.
    Best regards
    Francesco

    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #27762

    brio
    Participant

    Hi Dimitar,
    that’s the effect I was needing.
    Matter is I’m not using a visible array; I’m connecting to a mysql db.

    here is my simplified code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <link rel="stylesheet" href="jqwidgets/styles/jqx.classic.css" type="text/css" />
    <script type="text/javascript" src="scripts/gettheme.js"></script>
    <script type="text/javascript" src="scripts/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.maskedinput.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxexpander.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxnumberinput.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxvalidator.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    var theme = getDemoTheme();
    $("#jqxinput").jqxInput(
    {
    theme: theme,
    width: 200,
    height: 25,
    minLength: 2,
    source: function(query, response) {
    var dataAdapter = new $.jqx.dataAdapter
    (
    {
    datatype: "json",
    datafields: [{name: 'comune', type: 'string'}],
    url: 'data.php'
    },
    {
    autoBind: true,
    formatData: function(data) {
    data.query = query;
    return data;
    },
    loadComplete: function(data) {
    if (data.length > 0) {
    response($.map(data, function(item) {
    return item.comune;
    }));
    }
    }
    }
    );
    }
    });
    $("#jqxinput").on("blur", function() {
    //how can I adapt Dimitar's code???
    });
    });
    </script>
    <style type="text/css">
    .text-input
    {
    height: 21px;
    width: 150px;
    }
    .register-table
    {
    margin-top: 10px;
    margin-bottom: 10px;
    }
    .register-table td,
    .register-table tr
    {
    margin: 0px;
    padding: 2px;
    border-spacing: 0px;
    border-collapse: collapse;
    font-family: Verdana;
    font-size: 12px;
    }
    h3
    {
    display: inline-block;
    margin: 0px;
    }
    </style>
    </head>
    <body class='default'>
    <div id="register">
    <div><h3>Registrazione</h3></div>
    <div>
    <form id="testForm" action="./">
    <table table class="register-table">
    <tr>
    <td>comune di residenza:</td>
    <td><input id="jqxinput"/></td>
    </tr>
    </table>
    </form>
    </div>
    </div>
    </body>
    </html>
    </body>
    </html>

    Just one help more, please.
    Thanks
    Francesco

    in reply to: jqxInput, autoselect on blur jqxInput, autoselect on blur #27715

    brio
    Participant

    Hi Dimitar,
    first of all thanks for answering; that’s quite what I’m intending to do.
    In your example, I’d like to force, on blur event, to choose the nearest suggested item or nothing.

    When user types “ro”, popup suggests “Romania”; if user leaves the input (on blur event), input chooses “Romania”.
    When user types “rtdf”, popup doen’t suggests anything; if user leaves the input (on blur event), input becomes blank.

    In my mind it’s something like:

    $("#input").on("blur", function () {
    if (popupdata.length > 0) {
    $('#input').jqxInput('val', popupdata.firsItem);
    };
    };

    What’s the right code?

    Thanks and best regards
    Francesco

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