Skip to content

Commit

Permalink
fix: reversed lint changes to cacadeForm (#312)
Browse files Browse the repository at this point in the history
* fix: remove display hardcoded style when unhiding elements using cascadeForm

* fix: removed changes made by linter

* fix: remove changes by linter
  • Loading branch information
jerotire authored Sep 6, 2024
1 parent ab6895b commit ac10eda
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions app/cdn/assets/_js/components/cascadeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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") {
Expand All @@ -121,6 +119,7 @@ OLCS.cascadeForm = (function (document, $, undefined) {
elem.attr("aria-hidden", "true");
elem.addClass("hidden");
}

}

/**
Expand All @@ -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);
}
Expand All @@ -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:
Expand All @@ -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");

}

/*
Expand All @@ -186,15 +181,18 @@ 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;
}
}

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);
});
}
Expand All @@ -205,4 +203,5 @@ OLCS.cascadeForm = (function (document, $, undefined) {

checkForm();
};
})(document, window.jQuery);

}(document, window.jQuery));

0 comments on commit ac10eda

Please sign in to comment.