jpkleemans / angular-validate

Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
MIT License
68 stars 32 forks source link

Error: element.validate is not a function #3

Closed SuperlativeEntity closed 8 years ago

SuperlativeEntity commented 8 years ago

I keep getting the following error:

element.validate is not a function

Sidenote: I'm using controller as

View

<div class="container">
    <div id="loginbox" style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
        <div class="panel panel-info">

            <div class="panel-heading">
                <div class="panel-title">Sign In</div>
            </div>

            <div style="padding-top:30px" class="panel-body">

                <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>

                <form id="loginform" class="form-horizontal" role="form" ng-validate="login.validationOptions">

                    <div style="margin-bottom: 25px" class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                        <input id="login-username" type="email" class="form-control" name="username" value="" ng-model="login.username" placeholder="email">
                    </div>

                    <div style="margin-bottom: 25px" class="input-group">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                        <input id="login-password" type="password" class="form-control" name="password" ng-model="login.password" placeholder="password">
                    </div>

                    <div style="margin-top:10px" class="form-group">
                        <div class="col-sm-12 controls">
                            <a id="btn-login" ng-click="login.login()" class="btn btn-primary">Login</a>
                        </div>
                    </div>

                </form>

            </div>
        </div>
    </div>
</div>

Controller

function LoginController(user, auth, refreshToken, $location)
{
    var self = this;

    self.validationOptions =
    {
        rules:
        {
            username:
            {
                required: true,
                email: true
            },
            password:
            {
                required: true,
                minlength: 6
            }
        },
        messages:
        {
            username:
            {
                required: "Email Address is Required",
                email: "Your email address must be in the format of name@domain.com"
            },
            password: {
                required: "Password is Required",
                minlength: "Your password must have a minimum length of 6 characters"
            }
        }
    }
jpkleemans commented 8 years ago

Hi,

That error means that some of the required js files isn't being loaded or the order of loading is wrong (jquery before angular). Can you check if this is the case in your code?

SuperlativeEntity commented 8 years ago

I have it in the following order:

    <script src="vendor/angular/angular.js"></script>
    <script src="vendor/angular-route/angular-route.js"></script>

    <script src="vendor/jquery/jquery.js"></script>
    <script src="vendor/jquery/jquery.validate.js"></script>
    <script src="vendor/jquery/additional-methods.js"></script>
    <script src="vendor/angular-validate/angular-validate.js"></script>
jpkleemans commented 8 years ago

Hi,

jquery must be loaded before angular!

SuperlativeEntity commented 8 years ago

Thanks, seems to be grafting

Toomavic commented 7 years ago

hello

I am using the plugin with ionic and this is my files order

`

<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="lib/jquery/dist/jquery.min.js"></script>
<script src="lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="lib/jquery-validation/dist/additional-methods.min.js"></script>
<script src="lib/jpkleemans-angular-validate/src/angular-validate.js"></script>`

and I am getting same error. Could anyone help! please

jpkleemans commented 7 years ago

Hi,

Try to load jquery before ionic.bundle.js.

Toomavic commented 7 years ago

Yeah Thanks I just did it before your replay. Thanks Alot Life Saver 👍 👍 💯