From 0803dc1133d39a807e44d12e78bd198a2ca27917 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 13 Apr 2018 19:23:51 +0200 Subject: [PATCH] Fix #44 --- Views/FormView.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Views/FormView.js b/Views/FormView.js index c082533..9cf6f35 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -151,7 +151,31 @@ canvas = form.getElementsByTagName('canvas'), external = document.querySelectorAll('[form=' + this.id + ']'); - return Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external)); + return this.getUniqueFormElements( + Array.prototype.slice.call(inputs).concat( + Array.prototype.slice.call(selects), + Array.prototype.slice.call(textareas), + Array.prototype.slice.call(external) + ) + ); + }; + + /** + * Get unique form elements + * + * @param {Array} arr Form element array + * + * @return {Array} + * + * @since 1.0.0 + */ + jsOMS.Views.FormView.prototype.getUniqueFormElements = function (arr) + { + let seen = {}; + + return arr.filter(function(item) { + return seen.hasOwnProperty(item.name) ? false : (seen[item.name] = true); + }); }; /**