-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (109 loc) · 4.21 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html lang="en">
<head>
<title>Builder</title>
<!-- Latest compiled and minified CSS -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.1/css/bootstrapValidator.min.css" />
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.1/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
var _js = [];
var messages = {
'notEmpty': 'The value is required',
'emailAddress': 'The value is not a valid email address',
};
$(function() {
$('#validator').on('change', function() {
$('#message').val(messages[this.value]);
});
$('#addRule').on('click', function() {
_js.push({
fieldName: $('#fieldName').val(),
validators: $('#validator').val()[0],
message: $('#message').val()
});
//$('#form-builder').reset();
console.log(_js);
renderjs();
});
});
renderjs = function() {
var js = "<pre> $(document).ready(function() { <br>\
$('#profileForm').bootstrapValidator({ <br>\
feedbackIcons: { <br>\
valid: 'glyphicon glyphicon-ok', <br>\
invalid: 'glyphicon glyphicon-remove', <br>\
validating: 'glyphicon glyphicon-refresh' <br>\
},\
fields: { <br>\
";
$.each(_js, function(key, rule) {
js += "" + rule.fieldName + ": { <br>\
validators: { <br>\
" + rule.validators + ": { <br>\
message: '" + rule.message + "' <br>\
}, <br>\
} <br>\
"
});
js += "\
} <br>\
} <br>\
}); <br>\
}); <br>\
</pre>";
$('#render-js').html(js);
}
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Validation Builder
<small>Build the Validation</small>
</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="well">
<h2>Builder</h2>
<form role="form" id="form-builder">
<div class="form-group">
<label for="fieldName">Name / ID</label>
<input type="input" class="form-control" id="fieldName" required placeholder="Field Name">
</div>
<div class="form-group">
<label for="fieldName">Validator</label>
<select class="form-control" name="validator" id="validator" class="validator" multiple>
<option value="notEmpty">Required</option>
<option value="emailAddress">emailAddress</option>
</select>
</div>
<div class="form-group">
<label for="message">Message</label>
<input type="input" class="form-control" id="message" placeholder="Message">
</div>
<button type="button" class="btn btn-default" id="addRule">Add</button>
</form>
</div>
</div>
<div class="col-md-6">
<div class="well">
<h2>Render</h2>
<div id="render-js">
</div>
</div>
</div>
</div>
</div>
</body>
</html>