Skip to content

Commit

Permalink
Added tests for :horizontal_form wrapper and made it pass
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalRemis committed Apr 17, 2020
1 parent f28196b commit 887564b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions dist/simple-form.bootstrap4.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = {
wrappers: {
"default": {
add: function add(element, settings, message) {
var wrapperElement = element.parent();
var parentElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');

if (!errorElement.length) {
errorElement = $('<' + settings.error_tag + '>', {
"class": 'invalid-feedback',
text: message
});
wrapperElement.append(errorElement);
parentElement.append(errorElement);
}

wrapperElement.addClass(settings.wrapper_error_class);
element.addClass('is-invalid');
errorElement.text(message);
},
remove: function remove(element, settings) {
var wrapperElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');
wrapperElement.removeClass(settings.wrapper_error_class);
element.removeClass('is-invalid');
Expand Down
7 changes: 4 additions & 3 deletions dist/simple-form.bootstrap4.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@
wrappers: {
"default": {
add: function add(element, settings, message) {
var wrapperElement = element.parent();
var parentElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');

if (!errorElement.length) {
errorElement = $('<' + settings.error_tag + '>', {
"class": 'invalid-feedback',
text: message
});
wrapperElement.append(errorElement);
parentElement.append(errorElement);
}

wrapperElement.addClass(settings.wrapper_error_class);
element.addClass('is-invalid');
errorElement.text(message);
},
remove: function remove(element, settings) {
var wrapperElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');
wrapperElement.removeClass(settings.wrapper_error_class);
element.removeClass('is-invalid');
Expand Down
8 changes: 5 additions & 3 deletions src/main.bootstrap4.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = {
wrappers: {
default: {
add (element, settings, message) {
const wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/\ /g, '.'));
const parentElement = element.parent()
const wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'))

let errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback')

if (!errorElement.length) {
errorElement = $('<' + settings.error_tag + '>', { class: 'invalid-feedback', text: message })
wrapperElement.append(errorElement)
parentElement.append(errorElement)
}

wrapperElement.addClass(settings.wrapper_error_class)
Expand All @@ -29,7 +31,7 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = {
},

remove (element, settings) {
const wrapperElement = settings.wrapper_tag + "." + settings.wrapper_class.replace(/\ /g, ".")
const wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'))
const errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback')

wrapperElement.removeClass(settings.wrapper_error_class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@
wrappers: {
"default": {
add: function add(element, settings, message) {
var wrapperElement = element.parent();
var parentElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');

if (!errorElement.length) {
errorElement = $('<' + settings.error_tag + '>', {
"class": 'invalid-feedback',
text: message
});
wrapperElement.append(errorElement);
parentElement.append(errorElement);
}

wrapperElement.addClass(settings.wrapper_error_class);
element.addClass('is-invalid');
errorElement.text(message);
},
remove: function remove(element, settings) {
var wrapperElement = element.parent();
var wrapperElement = element.closest(settings.wrapper_tag + '.' + settings.wrapper_class.replace(/ /g, '.'));
var errorElement = wrapperElement.find(settings.error_tag + '.invalid-feedback');
wrapperElement.removeClass(settings.wrapper_error_class);
element.removeClass('is-invalid');
Expand Down

0 comments on commit 887564b

Please sign in to comment.