|
|
@@ -0,0 +1,103 @@
|
|
|
+<!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">
|
|
|
+ <!-- form: -->
|
|
|
+ <section>
|
|
|
+ <div class="col-lg-8 col-lg-offset-2">
|
|
|
+ <div class="page-header">
|
|
|
+ <h2>Dynamic fields</h2>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-lg-3 control-label">Question</label>
|
|
|
+ <div class="col-lg-5">
|
|
|
+ <input class="form-control" type="text" name="question" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-lg-3 control-label">Answers</label>
|
|
|
+ <div class="col-lg-5">
|
|
|
+ <input class="form-control" type="text" name="answers[]" />
|
|
|
+ </div>
|
|
|
+ <div class="col-lg-2">
|
|
|
+ <button type="button" class="btn btn-default btn-sm addButton">Add</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-group hide" id="template">
|
|
|
+ <div class="col-lg-offset-3 col-lg-5">
|
|
|
+ <input class="form-control" type="text" name="answers[]" />
|
|
|
+ </div>
|
|
|
+ <div class="col-lg-2">
|
|
|
+ <button type="button" class="btn btn-default btn-sm removeButton">Remove</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="form-group">
|
|
|
+ <div class="col-lg-offset-3 col-lg-3">
|
|
|
+ <button type="submit" class="btn btn-primary">Submit</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
+ <!-- :form -->
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+
|
|
|
+<script type="text/javascript">
|
|
|
+ $(document).ready(function() {
|
|
|
+ // Add button click handler
|
|
|
+ $('.addButton').on('click', function() {
|
|
|
+ var $row = $('#template').clone().removeAttr('id').insertBefore($('#template')).removeClass('hide');
|
|
|
+
|
|
|
+ var $answer = $row.find('[name="answers[]"]');
|
|
|
+ $('#defaultForm').bootstrapValidator('addFieldElement', $answer);
|
|
|
+
|
|
|
+ $row.on('click', '.removeButton', function(e) {
|
|
|
+ $row.remove();
|
|
|
+ $('#defaultForm').bootstrapValidator('removeFieldElement', $answer);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#defaultForm').bootstrapValidator({
|
|
|
+ message: 'This value is not valid',
|
|
|
+ feedbackIcons: {
|
|
|
+ valid: 'glyphicon glyphicon-ok',
|
|
|
+ invalid: 'glyphicon glyphicon-remove',
|
|
|
+ validating: 'glyphicon glyphicon-refresh'
|
|
|
+ },
|
|
|
+ fields: {
|
|
|
+ question: {
|
|
|
+ validators: {
|
|
|
+ notEmpty: {
|
|
|
+ message: 'The gender is required'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'answers[]': {
|
|
|
+ validators: {
|
|
|
+ notEmpty: {
|
|
|
+ message: 'The answer is required'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+</script>
|
|
|
+</body>
|
|
|
+</html>
|