浏览代码

#17: Support default Bootstrap form without labels

nghuuphuoc 12 年之前
父节点
当前提交
ae3caffd0b

+ 109 - 0
demo/formWithoutLabels.html

@@ -0,0 +1,109 @@
+<!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" style="margin-top: 50px;">
+        <div class="row">
+            <div class="col-lg-4 col-lg-offset-4">
+                <div class="panel panel-default">
+                    <div class="panel-heading">
+                        <h3 class="panel-title">Sign up</h3>
+                    </div>
+
+                    <div class="panel-body">
+                        <form id="defaultForm" method="post">
+                            <div class="form-group">
+                                <input type="text" class="form-control" name="username" placeholder="Username" />
+                            </div>
+
+                            <div class="form-group">
+                                <input type="text" class="form-control" name="email" placeholder="Email" />
+                            </div>
+
+                            <div class="form-group">
+                                <input type="password" class="form-control" name="password" placeholder="Password" />
+                            </div>
+
+                            <div class="form-group">
+                                <input type="password" class="form-control" name="confirmPassword" placeholder="Retype password" />
+                            </div>
+
+                            <div class="form-group">
+                                <button type="submit" class="btn btn-primary">Sign up</button>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+
+<script type="text/javascript">
+$(document).ready(function() {
+    $('#defaultForm').bootstrapValidator({
+        message: 'This value is not valid',
+        fields: {
+            username: {
+                message: 'The username is not valid',
+                validators: {
+                    notEmpty: {
+                        message: 'The username is required and can\'t be empty'
+                    },
+                    stringLength: {
+                        min: 6,
+                        max: 30,
+                        message: 'The username must be more than 6 and less than 30 characters long'
+                    },
+                    regexp: {
+                        regexp: /^[a-zA-Z0-9_\.]+$/,
+                        message: 'The username can only consist of alphabetical, number, dot and underscore'
+                    }
+                }
+            },
+            email: {
+                validators: {
+                    notEmpty: {
+                        message: 'The email address is required and can\'t be empty'
+                    },
+                    emailAddress: {
+                        message: 'The input is not a valid email address'
+                    }
+                }
+            },
+            password: {
+                validators: {
+                    notEmpty: {
+                        message: 'The password is required and can\'t be empty'
+                    },
+                    identical: {
+                        field: 'confirmPassword',
+                        message: 'The password and its confirm are not the same'
+                    }
+                }
+            },
+            confirmPassword: {
+                validators: {
+                    notEmpty: {
+                        message: 'The confirm password is required and can\'t be empty'
+                    },
+                    identical: {
+                        field: 'password',
+                        message: 'The password and its confirm are not the same'
+                    }
+                }
+            }
+        }
+    });
+});
+</script>
+</body>
+</html>

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -1,5 +1,5 @@
 /**
- * BootstrapValidator v0.1.0 (http://github.com/nghuuphuoc/bootstrapvalidator)
+ * BootstrapValidator v0.1.1-dev (http://github.com/nghuuphuoc/bootstrapvalidator)
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *

+ 4 - 2
dist/js/bootstrapValidator.js

@@ -1,5 +1,5 @@
 /**
- * BootstrapValidator v0.1.0 (http://github.com/nghuuphuoc/bootstrapvalidator)
+ * BootstrapValidator v0.1.1-dev (http://github.com/nghuuphuoc/bootstrapvalidator)
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *
@@ -119,7 +119,9 @@
                         }
                     }
                 }
-                $small.addClass('col-lg-offset-' + offset).addClass('col-lg-' + parseInt(12 - offset));
+                if (offset) {
+                    $small.addClass('col-lg-offset-' + offset).addClass('col-lg-' + parseInt(12 - offset));
+                }
             } else {
                 $field.data('bootstrapValidator.error', helpBlock.eq(0));
             }

文件差异内容过多而无法显示
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 1 - 1
package.json

@@ -13,5 +13,5 @@
     "grunt-contrib-cssmin": "~0.6.2",
     "grunt-contrib-copy": "~0.4.1"
   },
-  "version": "0.1.0"
+  "version": "0.1.1-dev"
 }

+ 3 - 1
src/js/bootstrapValidator.js

@@ -119,7 +119,9 @@
                         }
                     }
                 }
-                $small.addClass('col-lg-offset-' + offset).addClass('col-lg-' + parseInt(12 - offset));
+                if (offset) {
+                    $small.addClass('col-lg-offset-' + offset).addClass('col-lg-' + parseInt(12 - offset));
+                }
             } else {
                 $field.data('bootstrapValidator.error', helpBlock.eq(0));
             }