From 8e3338dbc73d6b5cca8e8539856386dad02d1570 Mon Sep 17 00:00:00 2001 From: JapSeyz Date: Sun, 19 Jun 2016 15:06:57 +0200 Subject: [PATCH 1/2] Replaced manual function with existing one. --- public/assets/javascript/app-public.js | 19 ++----------------- public/assets/javascript/frontend.js | 19 ++----------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/public/assets/javascript/app-public.js b/public/assets/javascript/app-public.js index a4638b0c..073d0d94 100644 --- a/public/assets/javascript/app-public.js +++ b/public/assets/javascript/app-public.js @@ -53,24 +53,9 @@ $(function() { case 'error': if (data.messages) { - $.each(data.messages, function(index, error) { - - /* - * use the class as the selector if the input name is an array. - */ - var selector = (index.indexOf(".") >= 0) ? '.' + index.replace(/\./g, "\\.") : ':input[name=' + index + ']'; - - $(selector, $form) - .after('
' + error + '
') - .parent() - .addClass('has-error'); - }); + processFormErrors($form, data.messages); + return; } - - - var $submitButton = $form.find('input[type=submit]'); - toggleSubmitDisabled($submitButton); - break; default: diff --git a/public/assets/javascript/frontend.js b/public/assets/javascript/frontend.js index ae0bba96..0b8b2c2f 100644 --- a/public/assets/javascript/frontend.js +++ b/public/assets/javascript/frontend.js @@ -3956,24 +3956,9 @@ function log() { case 'error': if (data.messages) { - $.each(data.messages, function(index, error) { - - /* - * use the class as the selector if the input name is an array. - */ - var selector = (index.indexOf(".") >= 0) ? '.' + index.replace(/\./g, "\\.") : ':input[name=' + index + ']'; - - $(selector, $form) - .after('
' + error + '
') - .parent() - .addClass('has-error'); - }); + processFormErrors($form, data.messages); + return; } - - - var $submitButton = $form.find('input[type=submit]'); - toggleSubmitDisabled($submitButton); - break; default: From a44e951f72cf9eb11606b07fc3e9af33eb0300fe Mon Sep 17 00:00:00 2001 From: Jesper Jacobsen Date: Thu, 23 Jun 2016 16:24:22 +0200 Subject: [PATCH 2/2] Added array validation to ProcessFormErrors --- public/assets/javascript/app-public.js | 3 ++- public/assets/javascript/frontend.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/assets/javascript/app-public.js b/public/assets/javascript/app-public.js index 073d0d94..7195f83c 100644 --- a/public/assets/javascript/app-public.js +++ b/public/assets/javascript/app-public.js @@ -163,7 +163,8 @@ function processFormErrors($form, errors) { $.each(errors, function (index, error) { - var $input = $(':input[name=' + index + ']', $form); + var selector = (index.indexOf(".") >= 0) ? '.' + index.replace(/\./g, "\\.") : ':input[name=' + index + ']'; + var $input = $(selector, $form); if ($input.prop('type') === 'file') { $('#input-' + $input.prop('name')).append('
' + error + '
') diff --git a/public/assets/javascript/frontend.js b/public/assets/javascript/frontend.js index 0b8b2c2f..b8ec3741 100644 --- a/public/assets/javascript/frontend.js +++ b/public/assets/javascript/frontend.js @@ -4066,7 +4066,8 @@ function processFormErrors($form, errors) { $.each(errors, function (index, error) { - var $input = $(':input[name=' + index + ']', $form); + var selector = (index.indexOf(".") >= 0) ? '.' + index.replace(/\./g, "\\.") : ':input[name=' + index + ']'; + var $input = $(selector, $form); if ($input.prop('type') === 'file') { $('#input-' + $input.prop('name')).append('
' + error + '
')