JB's
JB's

Reputation: 626

Parsley JS not validating

I am trying to validate my form using parsley.js, I am working as the official good book says to do so but due to some reasons (that I obviously don't know right now), it is not working.

Here is the code

<div class="container">
        <div class="row">
            <div class="col-md-4">
                <h2>Parsley JS Form Validation</h2>
                <form data-validate="parsley">
                    <label>Name </label>
                    <input type="text" name="fname"  class="form-control" required />
                    <label>Email </label>
                    <input type="text" name="email" class="form-control" data-type="email" data-trigger="change" required />
                    <label>Password </label>
                    <input type="text" name="lname"  class="form-control" data-type="password" required />
                    <br />
                    <input type="submit" class="btn btn-success" value="Submit">
                </form>
            </div>
        </div>
    </div>

Here is the Plunkr link.

Upvotes: 0

Views: 6753

Answers (2)

JB&#39;s
JB&#39;s

Reputation: 626

The problem was is was using data-required instead I have to use data-parsley-required and also instead of data-validate="parsley" it should be data-parsley-validate="parsley"

Plunkr modified

Upvotes: 1

Apostolos
Apostolos

Reputation: 10463

I dont know how to save it so I'm posting it here: I changed the jquery version, the parsley version (you used an old one), and also added the css from parsley site. Your tag attributes were wrong. this works:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Parsley JS</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
        <link href="https://parsleyjs.org/src/parsley.css" rel="stylesheet" />
        <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.3.4/parsley.min.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <h2>Parsley JS Form Validation</h2>
                    <form data-parsley-validate="parsley">
                        <label>Name </label>
                        <input type="text" name="fname" class="form-control" required="true" />
                        <label>Email </label>
                        <input name="email" class="form-control" type="email" data-parsley-trigger="change" required="true" />
                        <label>Password </label>
                        <input  name="lname"  class="form-control" type="password" required="true" />
                        <br />
                        <input type="submit" class="btn btn-success" value="Submit">
                    </form>
                </div>
            </div>
        </div>        
    </body>
</html>

Upvotes: 2

Related Questions