admin管理员组文章数量:1429515
I am trying to validate username and password field using bootstrap validator
I have included css and js for bootstrap validator.
form id to validate is #login
Code is as below
<head>
<script type='text/javascript' src='js/jquery-2.1.1.min.js'></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<link rel="stylesheet" href="js/bootstrap-3.1.1-dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="js/bootstrap-3.1.1-dist/css/bootstrap-theme.min.css"/>
<script type='text/javascript' src="js/bootstrapvalidator-dist-0.4.5/dist/js/bootstrapValidator.min.js"></script>
<script type='text/javascript' src="js/bootstrapvalidator-dist-0.4.5/dist/css/bootstrapValidator.min.css"></script>
<script>
$(document).ready(function() {
$('#login').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
userName: {
validators: {
notEmpty: {
message: 'User Name required'
}
}
},
password: {
validators: {
notEmpty: {
message: 'TPassword required'
}
}
}
}
});
});</script>
</head>
<body>
<form action="login" method="post" id="login" >
<div class="form-group">
<label class="control-label" for="userName">
User Id
</label>
<input type="text" placeholder="Username" name="userName" id="userName" class="form-control lgn">
</div>
<div class="form-group">
<label class="control-label" for="Password">
Password
</label>
<input type="password" placeholder="Password" name="password" id="password" class="form-control lgn">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success lgn" >Login</button>
</div>
</form>
</body>
How to resolve this.
fiddle demo jsfiddle/xrcwrn/3bthv
I am trying to validate username and password field using bootstrap validator
I have included css and js for bootstrap validator.
form id to validate is #login
Code is as below
<head>
<script type='text/javascript' src='js/jquery-2.1.1.min.js'></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<link rel="stylesheet" href="js/bootstrap-3.1.1-dist/css/bootstrap.min.css"/>
<link rel="stylesheet" href="js/bootstrap-3.1.1-dist/css/bootstrap-theme.min.css"/>
<script type='text/javascript' src="js/bootstrapvalidator-dist-0.4.5/dist/js/bootstrapValidator.min.js"></script>
<script type='text/javascript' src="js/bootstrapvalidator-dist-0.4.5/dist/css/bootstrapValidator.min.css"></script>
<script>
$(document).ready(function() {
$('#login').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
userName: {
validators: {
notEmpty: {
message: 'User Name required'
}
}
},
password: {
validators: {
notEmpty: {
message: 'TPassword required'
}
}
}
}
});
});</script>
</head>
<body>
<form action="login" method="post" id="login" >
<div class="form-group">
<label class="control-label" for="userName">
User Id
</label>
<input type="text" placeholder="Username" name="userName" id="userName" class="form-control lgn">
</div>
<div class="form-group">
<label class="control-label" for="Password">
Password
</label>
<input type="password" placeholder="Password" name="password" id="password" class="form-control lgn">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success lgn" >Login</button>
</div>
</form>
</body>
How to resolve this.
fiddle demo jsfiddle/xrcwrn/3bthv
Share Improve this question edited Jul 27, 2014 at 11:59 xrcwrn asked Jul 26, 2014 at 16:11 xrcwrnxrcwrn 5,33717 gold badges71 silver badges130 bronze badges1 Answer
Reset to default 1Here is a working fiddle
The problem was that your js code contained in the fiddle contained syntax errors. The console should be the first thing you check when your javascript isn't working as expected. I mented in the code below what changes I made to get the fiddle to work. (It looks like the code in your question is fine though)
$(document).ready(function() {
$('#login').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
userName: {
validators: {
notEmpty: {
message: 'The first name is required and cannot be empty'
}
}
},
password: {
validators: {
notEmpty: {
message: 'The last name is required and cannot be empty'
}
}
} /* <-- removed unneeded ma */
} /* <-- added closing brace */
});
});
本文标签: javascriptBootstrap form validation not workingStack Overflow
版权声明:本文标题:javascript - Bootstrap form validation not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745494794a2660759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论