forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event2.html
89 lines (84 loc) · 3.53 KB
/
event2.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
<!DOCTYPE html>
<html>
<head>
<title>FormValidation demo</title>
<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="../dist/css/formValidation.css"/>
<script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../dist/js/formValidation.js"></script>
<script type="text/javascript" src="../dist/js/framework/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="page-header">
<h2>Using events</h2>
</div>
<form id="pickupForm" method="post" class="form-horizontal" action="target.php">
<div class="form-group">
<label class="col-lg-3 control-label">Postal Code<sup>*</sup></label>
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">Singapore</span>
<input type="text" class="form-control" name="postalCode" placeholder="Postal Code" />
</div>
</div>
<div class="col-lg-1">
<button type="button" class="btn btn-default" id="lookupBtn">Lookup Address</button>
</div>
</div>
<div class="form-group">
<div class="col-lg-9 col-lg-offset-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#pickupForm')
.formValidation({
message: 'This value is not valid',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
postalCode: {
message: 'The postal code is not valid',
validators: {
notEmpty: {
message: 'Your postal code is required and cannot be empty'
},
regexp: {
regexp: /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/,
message: 'The input is not a valid Singapore postal code'
},
numeric: {
message: 'Only numbers are allowed'
}
}
}
}
})
.on('err.field.fv', function(e, data) {
if (data.field == 'postalCode') {
// The postal code is not valid
$('#lookupBtn').prop('disabled', true).removeClass('btn-success btn-warning').addClass('btn-warning');
}
})
.on('success.field.fv', function(e, data) {
if (data.field == 'postalCode') {
// The postal code is valid
$('#lookupBtn').prop('disabled', false).removeClass('btn-success btn-warning').addClass('btn-success');
}
});
});
</script>
</body>
</html>