diff --git a/views/bootstrap/styles/validation-default.js b/views/bootstrap/styles/validation-default.js new file mode 100644 index 000000000..a7c064cfc --- /dev/null +++ b/views/bootstrap/styles/validation-default.js @@ -0,0 +1,34 @@ +jQuery.validator.setDefaults({ + errorElement: "em", + errorClass: 'help-block', + errorPlacement: function ( error, element ) { + // Add the `error` class to the control-group + $(element).closest('.control-group').addClass('error'); + if ( element.prop( "type" ) === "checkbox" ) { + error.insertAfter( element.parent( "label" ) ); + } else { + error.insertAfter( element ); + } + + // Add the span element, if doesn't exists, and apply the icon classes to it. + if ( !element.next( "span" )[ 0 ] ) { + $( "" ).insertAfter( element ); + } + }, + invalidHandler: function(e, validator) { + noty({ + text: (validator.numberOfInvalids() == 1) ? trans.js_form_error.replace('#', validator.numberOfInvalids()) : trans.js_form_errors.replace('#', validator.numberOfInvalids()), + type: 'error', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 3500, + }); + }, + highlight: function ( element, errorClass, validClass ) { + $( element ).parents( ".control-group" ).addClass( "error" ).removeClass( "success" ); + }, + unhighlight: function ( element, errorClass, validClass ) { + $( element ).parents( ".control-group" ).addClass( "success" ).removeClass( "error" ); + } +}); diff --git a/views/bootstrap4/styles/validation-default.js b/views/bootstrap4/styles/validation-default.js new file mode 100644 index 000000000..88f77a4ad --- /dev/null +++ b/views/bootstrap4/styles/validation-default.js @@ -0,0 +1,33 @@ +jQuery.validator.setDefaults({ + errorElement: 'div', + errorClass: 'invalid-feedback', + errorPlacement: function(error, element) { + if(element.parent('.input-group').length) { + error.insertAfter(element.parent()); + } else { + error.insertAfter(element); + } + }, + invalidHandler: function(e, validator) { + noty({ + text: (validator.numberOfInvalids() == 1) ? trans.js_form_error.replace('#', validator.numberOfInvalids()) : trans.js_form_errors.replace('#', validator.numberOfInvalids()), + type: 'error', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 3500, + }); + }, + highlight: function (element, errorClass, validClass) { + if($(element).data('target-highlight')) + $('#'+$(element).data('target-highlight')).addClass('is-invalid'); + else + $(element).addClass('is-invalid'); + }, + unhighlight: function (element, errorClass, validClass) { + if($(element).data('target-highlight')) + $('#'+$(element).data('target-highlight')).removeClass('is-invalid'); + else + $(element).removeClass('is-invalid'); + } +});