From aa3954ecbbc465a171e1bfac73fd52ef3785d6dc Mon Sep 17 00:00:00 2001 From: Michal Remis Date: Wed, 15 Apr 2020 00:29:35 +0200 Subject: [PATCH] Added tests for :horizontal_form wrapper and made it pass --- dist/simple-form.bootstrap4.esm.js | 7 ++++--- dist/simple-form.bootstrap4.js | 7 ++++--- src/main.bootstrap4.js | 8 +++++--- .../rails.validations.simple_form.bootstrap4.js | 7 ++++--- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/dist/simple-form.bootstrap4.esm.js b/dist/simple-form.bootstrap4.esm.js index 5cf2108..d0462c2 100644 --- a/dist/simple-form.bootstrap4.esm.js +++ b/dist/simple-form.bootstrap4.esm.js @@ -20,7 +20,8 @@ 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) { @@ -28,7 +29,7 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = { "class": 'invalid-feedback', text: message }); - wrapperElement.append(errorElement); + parentElement.append(errorElement); } wrapperElement.addClass(settings.wrapper_error_class); @@ -36,7 +37,7 @@ ClientSideValidations.formBuilders['SimpleForm::FormBuilder'] = { 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'); diff --git a/dist/simple-form.bootstrap4.js b/dist/simple-form.bootstrap4.js index e5bd428..15c3089 100644 --- a/dist/simple-form.bootstrap4.js +++ b/dist/simple-form.bootstrap4.js @@ -26,7 +26,8 @@ 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) { @@ -34,7 +35,7 @@ "class": 'invalid-feedback', text: message }); - wrapperElement.append(errorElement); + parentElement.append(errorElement); } wrapperElement.addClass(settings.wrapper_error_class); @@ -42,7 +43,7 @@ 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'); diff --git a/src/main.bootstrap4.js b/src/main.bootstrap4.js index 7c4175a..01e2e4e 100644 --- a/src/main.bootstrap4.js +++ b/src/main.bootstrap4.js @@ -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) @@ -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) diff --git a/vendor/assets/javascripts/rails.validations.simple_form.bootstrap4.js b/vendor/assets/javascripts/rails.validations.simple_form.bootstrap4.js index e5bd428..15c3089 100644 --- a/vendor/assets/javascripts/rails.validations.simple_form.bootstrap4.js +++ b/vendor/assets/javascripts/rails.validations.simple_form.bootstrap4.js @@ -26,7 +26,8 @@ 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) { @@ -34,7 +35,7 @@ "class": 'invalid-feedback', text: message }); - wrapperElement.append(errorElement); + parentElement.append(errorElement); } wrapperElement.addClass(settings.wrapper_error_class); @@ -42,7 +43,7 @@ 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');