BootsrapValidator不适用于Backbone View

时间:2014-12-08 16:09:30

标签: javascript forms twitter-bootstrap backbone.js requirejs

我有一个更改密码的表单

    <form class="form-horizontal" id="passwordForm" role="form">

        <div class = "form-group">
            <label for = "passworActuel" class = "col-sm-1 control-label" >Password actuel</label>
            <div class = "col-sm-3">
                <input type = "password" id = "passwordActuel" name = "passwordActuel" class = "form-control" placeholder = "Password actuel"/>
            </div>
        </div>

        <div class = "form-group">
            <div class = 'col-sm-offset-1'>
                <button type = "submit" class = "btn btn-default" >Enregistrer</button>
            </div>
        </div>

    </form>

我有我的骨干视图:

define([... , 'bootstrapValidator', ...],
function(..., bootstrapValidator, ...){

    var validator = function(){
        $(document).ready(function() {
            $('#passwordForm').bootstrapValidator({
                fields:{
                    passwordActuel:{
                        validators:{
                            notEmpty:{
                                message : "Le champs du mot de passe actuel doit être renseigné"
                            }
                        }
                    }
                }
            });
        });
    };

    var ChangePasswordView = Backbone.View.extend({

        render : function(){
            this.$el.html(ChangePasswordTemplate());
            validator();

            return this;
        }
    });

    return ChangePasswordView;
});

表单出现但我的字段未经bootsrapValidator验证。我的consonle没有错误。我想也许验证器可以在模板之前加载。

0 个答案:

没有答案