Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #12 - Coral Select with multiple values #13

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<body>

<release version="1.10.4" date="not released">
<action type="update" dev="rubnig" issue="13">
Granite UI Show/Hide: Support multiple options for Coral select component.
</action>
<action type="fix" dev="sseifert" issue="10">
DummyPageContext: Wrap existing servlet response writer for provided JspWriter.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
});
}

function includesCommaSeparated(valuesString, value) {
function includesCommaSeparated(valuesString, values) {
if (valuesString) {
return valuesString.split(",").find(item => item === value) != undefined
return valuesString.split(",").find(item => values.includes(item)) != undefined;
}
return false
}
Expand Down Expand Up @@ -75,25 +75,28 @@
$target = $(target);
}

var value;
var values = [];
if ($element.is("coral-checkbox") && typeof component.checked !== "undefined") {
value = component.checked ? "true" : "false";
values.push(component.checked ? "true" : "false");
}
else if ($element.is("coral-select")) {
value = $element.children('coral-select-item[selected]').val() || "";
$element.children("coral-select-item[selected]").each(function(index, element) {
var value = $(element).val() || ""
values.push(value);
});
}
else if (typeof component.value !== "undefined") {
value = component.value;
values.push(component.value);
}
else if (typeof component.getValue === "function") {
value = component.getValue();
values.push(component.getValue());
}

$target.each(function(index, element) {
// make sure all unselected target elements are hidden.
// unhide the target element that contains the selected value as data-showhidetargetvalue attribute
var show = element && (element.dataset.showhidetargetvalue === value
|| includesCommaSeparated(element.dataset.showhidetargetvalues, value));
var show = element && (values.includes(element.dataset.showhidetargetvalue)
|| includesCommaSeparated(element.dataset.showhidetargetvalues, values));
setVisibilityAndHandleFieldValidation($(element), show);
});
}
Expand Down