55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
|
(function() {
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
// basic
|
||
|
$("#form").validate({
|
||
|
highlight: function( label ) {
|
||
|
$(label).closest('.form-group').removeClass('has-success').addClass('has-error');
|
||
|
},
|
||
|
success: function( label ) {
|
||
|
$(label).closest('.form-group').removeClass('has-error');
|
||
|
label.remove();
|
||
|
},
|
||
|
errorPlacement: function( error, element ) {
|
||
|
var placement = element.closest('.input-group');
|
||
|
if (!placement.get(0)) {
|
||
|
placement = element;
|
||
|
}
|
||
|
if (error.text() !== '') {
|
||
|
placement.after(error);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// validation summary
|
||
|
var $summaryForm = $("#summary-form");
|
||
|
$summaryForm.validate({
|
||
|
errorContainer: $summaryForm.find( 'div.validation-message' ),
|
||
|
errorLabelContainer: $summaryForm.find( 'div.validation-message ul' ),
|
||
|
wrapper: "li"
|
||
|
});
|
||
|
|
||
|
// checkbox, radio and selects
|
||
|
$("#chk-radios-form, #selects-form").each(function() {
|
||
|
$(this).validate({
|
||
|
highlight: function(element) {
|
||
|
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
|
||
|
},
|
||
|
success: function(element) {
|
||
|
$(element).closest('.form-group').removeClass('has-error');
|
||
|
},
|
||
|
errorPlacement: function( error, element ) {
|
||
|
var placement = $(element).parent();
|
||
|
|
||
|
placement.append(error);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// Select 2 Fields
|
||
|
$('select[data-plugin-selectTwo]').on('change', function() {
|
||
|
$(this).valid();
|
||
|
});
|
||
|
|
||
|
}).apply(this, [jQuery]);
|