| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>BootstrapValidator demo</title>
- <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
- <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
- <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
- <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
- <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="row">
- <section>
- <div class="col-lg-8 col-lg-offset-2">
- <div class="page-header">
- <h2><code>selector</code> example</h2>
- </div>
- <form id="sumForm" method="post" class="form-horizontal" action="target.php">
- <div class="form-group">
- <label class="col-lg-3 control-label">Percentage</label>
- <div class="col-lg-5">
- <input class="form-control percent" type="text" />
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-offset-3 col-lg-5">
- <input class="form-control percent" type="text" />
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-offset-3 col-lg-5">
- <input class="form-control percent" type="text" />
- </div>
- </div>
- <div class="form-group">
- <div class="col-lg-9 col-lg-offset-3">
- <button type="submit" class="btn btn-primary">Validate</button>
- </div>
- </div>
- </form>
- </div>
- </section>
- </div>
- </div>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#sumForm').bootstrapValidator({
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- },
- fields: {
- 'percentage': {
- selector: '.percent',
- validators: {
- notEmpty: {
- message: 'The percentage is required'
- },
- callback: {
- message: 'The sum must be 100',
- callback: function(value, validator) {
- var percentage = validator.getFieldElements('percentage'),
- length = percentage.length,
- sum = 0;
- for (var i = 0; i < length; i++) {
- sum += parseFloat($(percentage[i]).val());
- }
- if (sum == 100) {
- validator.updateStatus('percentage', 'VALID', 'callback');
- return true;
- }
- return false;
- }
- }
- }
- }
- }
- });
- });
- </script>
- </body>
- </html>
|