Autor Zpráva
majja01
Profil
dobrý den,
mám formulář který kontroluji přes jquery vše jsem našel zde
jediné co jsem však nenašel je kontrola 2 inputůjestli jsou stejné (heslo a heslo znovu)
chtěl bych se zeptat jestli to jde přej jquery nebo to musím přes klasický javascript?
pokud možno nějaký příklad ;-)
díky majja01
David123
Profil *
Ahoj, nešlo by to vytáhnout z tohohle dema: http://jquery.bassistance.de/validate/demo/ ? Přímo heslo a ověření hesla tam je a vypadá to, že jim to funguje :)
majja01
Profil
našel jsem to ale vůbec mi to nefunguje :( a navíc to potřebuje další 2 js soubory takže nic
Joker
Profil
majja01:
A v čem přesně je problém?
Kontrola, jestli se hodnoty inputů rovnají, je triviální: jedenInput.value == druhyInput.value.
Z jQuery objektu jde hodnotu získat i metodou val().
aDAm
Profil
majja01:
a používáš ten plugin nebo ne? Jaké dva další soubory potřebuješ? Stačí přeci jen jQuery knihovna a tato validační knihovna. Sám sem tuto knihovnu používal a nebyl žáden problém, stačí se jen držet dokumentace.
majja01
Profil
No dosud jsem používal tento způsob:
<form id="commentForm">
<input type="text" required>
<button type="sumbit">odeslat</button>
</form>
a potom nešel odeslat formulář dokud jsem to nevyplnil dokonce to šlo bez jquery a bez tohoto:
<script>
$("#commentForm").validate();
</script>
což jaksi nechápu!?
a pro kontrolu jednoho formuláře (viz níže) je tam toto:
<script>
$(document).ready(function() {
    $.mockjax({
        url: "emails.action",
        response: function(settings) {
            var email = settings.data.email,
                emails = ["glen@marketo.com", "george@bush.gov", "me@god.com", "aboutface@cooper.com", "steam@valve.com", "bill@gates.com"];
            this.responseText = "true";
            if ( $.inArray( email, emails ) !== -1 ) {
                this.responseText = "That's already taken.";
            }
        },
        responseTime: 500
    });

    $.mockjax({
        url: "users.action",
        response: function(settings) {
            var user = settings.data.username,
                users = ["asdf", "Peter", "Peter2", "George"];
            this.responseText = "true";
            if ( $.inArray( user, users ) !== -1 ) {
                this.responseText = "false";
            }
        },
        responseTime: 500
    });


    // validate signup form on keyup and submit
    var validator = $("#signupform").validate({
        rules: {
            firstname: "required",
            lastname: "required",
            username: {
                required: true,
                minlength: 2,
                remote: "users.action"
            },
            password: {
                required: true,
                minlength: 5
            },
            password_confirm: {
                required: true,
                minlength: 5,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true,
                remote: "emails.action"
            },
            dateformat: "required",
            terms: "required"
        },
        messages: {
            firstname: "Enter your firstname",
            lastname: "Enter your lastname",
            username: {
                required: "Enter a username",
                minlength: jQuery.format("Enter at least {0} characters"),
                remote: jQuery.format("{0} is already in use")
            },
            password: {
                required: "Provide a password",
                rangelength: jQuery.format("Enter at least {0} characters")
            },
            password_confirm: {
                required: "Repeat your password",
                minlength: jQuery.format("Enter at least {0} characters"),
                equalTo: "Enter the same password as above"
            },
            email: {
                required: "Please enter a valid email address",
                minlength: "Please enter a valid email address",
                remote: jQuery.format("{0} is already in use")
            },
            dateformat: "Choose your preferred dateformat",
            terms: " "
        },
        // the errorPlacement has to take the table layout into account
        errorPlacement: function(error, element) {
            if ( element.is(":radio") )
                error.appendTo( element.parent().next().next() );
            else if ( element.is(":checkbox") )
                error.appendTo ( element.next() );
            else
                error.appendTo( element.parent().next() );
        },
        // specifying a submitHandler prevents the default submit, good for the demo
        submitHandler: function() {
            alert("submitted!");
        },
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set &nbsp; as text for IE
            label.html("&nbsp;").addClass("checked");
        },
        highlight: function(element, errorClass) {
            $(element).parent().next().find("." + errorClass).removeClass("checked");
        }
    });

    // propose username by combining first- and lastname
    $("#username").focus(function() {
        var firstname = $("#firstname").val();
        var lastname = $("#lastname").val();
        if(firstname && lastname && !this.value) {
            this.value = (firstname + "." + lastname).toLowerCase();
        }
    });

});
</script>
to všechno pro formulář tento
a ještě tam musím dát:
jquery.js (to chápu)
jquery.validate.js (asi taky)
jquery.mockjax.js (nechápu proč ale bez toho to nefunguje)
a ještě mi to ke všemu kazí jquery plugin icheck :(
mohl by mi někdo pomoct se v tom orientovat
Joker
Profil
majja01:
a potom nešel odeslat formulář dokud jsem to nevyplnil dokonce to šlo bez jquery a bez tohoto
Atribut required je definovaný v HTML 5 specifikaci, takže novější prohlížeče s ním umějí pracovat už na úrovni prohlížeče.
Starší prohlížeče ne.
majja01
Profil
aha v tom případě le nechápu proč to mají jako exemple na hlavní stránce pluginu jQuery Validation Plugin to mě asi zmátlo
použiju jinačí plugin

Vaše odpověď

Mohlo by se hodit

Neumíte-li správně určit příčinu chyby, vkládejte odkazy na živé ukázky.
Užíváte-li nějakou cizí knihovnu, ukažte odpovídajícím, kde jste ji vzali.

Užitečné odkazy:

Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0