diff --git a/app/cdn/assets/_js/components/cascadeForm.js b/app/cdn/assets/_js/components/cascadeForm.js index 506c5c95b9..ea48ded4a9 100644 --- a/app/cdn/assets/_js/components/cascadeForm.js +++ b/app/cdn/assets/_js/components/cascadeForm.js @@ -9,10 +9,12 @@ var OLCS = OLCS || {}; * in some way by the input received in the current one. */ -OLCS.cascadeForm = (function (document, $, undefined) { +OLCS.cascadeForm = (function(document, $, undefined) { + "use strict"; return function init(options) { + var selector = options.form || "form"; var formSelector = selector; var previousFieldset; @@ -25,7 +27,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { // target fieldset and clears them out return function clear() { var elems = $(target).find(":input"); - $.each(elems, function (i, elem) { + $.each(elems, function(i, elem) { elem = $(elem); if (elem.is(":checked")) { elem.prop("checked", false); @@ -36,6 +38,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { }; } + // iterate over the form, checking the relevant rulesets function checkForm() { for (var fieldset in options.rulesets) { @@ -67,6 +70,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { * if so; although currently there are exceptions to this */ function triggerRule(group, selector, rule) { + var show; var elem; var action = "none"; @@ -95,17 +99,11 @@ OLCS.cascadeForm = (function (document, $, undefined) { action = "hide"; } OLCS.logger.verbose( - group + - " > " + - selector + - ", should show? (" + - show + - "), is visible? (" + - elem.is(":visible") + - "), action: (" + - action + - ")", - "cascadeForm", + group + " > " + selector + + ", should show? (" + show + "), is visible? (" + + elem.is(":visible") + "), action: (" + + action + ")", + "cascadeForm" ); if (action !== "none") { @@ -121,6 +119,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { elem.attr("aria-hidden", "true"); elem.addClass("hidden"); } + } /** @@ -129,6 +128,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { * the group itself rather than a child */ function findContainer(group, selector) { + if (selector === "*") { return OLCS.formHelper(group); } @@ -141,19 +141,16 @@ OLCS.cascadeForm = (function (document, $, undefined) { } if (selector.search(":") !== -1) { + parts = selector.split(":"); switch (parts[0]) { case "label": - return $(formSelector) - .find("label[for=" + parts[1] + "]") - .parents(".field"); + return $(formSelector).find("label[for=" + parts[1] + "]").parents(".field"); case "selector": return $(formSelector).find(parts[1]); case "date": - return $(formSelector) - .find("[name*=" + parts[1] + "]") - .parents(".field"); + return $(formSelector).find("[name*=" + parts[1] + "]").parents(".field"); case "parent": return $(formSelector).find(parts[1]).parent(); default: @@ -164,17 +161,15 @@ OLCS.cascadeForm = (function (document, $, undefined) { if (selector.search("=") !== -1) { // assume a name=value pair specifies a radio button with a given value parts = selector.split("="); - return ( - OLCS.formHelper - .findInput(group, parts[0]) - .filter("[value=" + parts[1] + "]") - // radios are always wrapped inside a label - .parents("label:last") - ); + return OLCS.formHelper.findInput(group, parts[0]) + .filter("[value=" + parts[1] + "]") + // radios are always wrapped inside a label + .parents("label:last"); } // otherwise assume a straight input name which we assume is inside a field container return OLCS.formHelper(group, selector).parents(".field"); + } /* @@ -186,7 +181,10 @@ OLCS.cascadeForm = (function (document, $, undefined) { for (var fieldset in options.rulesets) { var current = findContainer(fieldset, "*"); if (previousFieldset) { - $(previousFieldset).on("change", clearFieldset(current)); + $(previousFieldset).on( + "change", + clearFieldset(current) + ); } previousFieldset = current; } @@ -194,7 +192,7 @@ OLCS.cascadeForm = (function (document, $, undefined) { if (onSubmit) { // we'd like to use bind, but IE8 won't let us - $(document).on("submit", formSelector, function (e) { + $(document).on("submit", formSelector, function(e) { onSubmit.call($(formSelector), e); }); } @@ -205,4 +203,5 @@ OLCS.cascadeForm = (function (document, $, undefined) { checkForm(); }; -})(document, window.jQuery); + +}(document, window.jQuery));