|
|
@@ -24,17 +24,17 @@
|
|
|
<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" />
|
|
|
+ <input class="form-control percent" name="first" type="text" value="0" />
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
<div class="col-lg-offset-3 col-lg-5">
|
|
|
- <input class="form-control percent" type="text" />
|
|
|
+ <input class="form-control percent" name="second" type="text" value="0" />
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
<div class="col-lg-offset-3 col-lg-5">
|
|
|
- <input class="form-control percent" type="text" />
|
|
|
+ <input class="form-control percent" name="third" type="text" value="0" />
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
@@ -50,40 +50,42 @@
|
|
|
|
|
|
<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;
|
|
|
- }
|
|
|
+ $('#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;
|
|
|
|
|
|
- return false;
|
|
|
+ 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>
|