-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - start javascript for domain filter widget
Domain will have top level and subdomain selections, and work similarly to "Topic/Sub-Topic" on GOV.UK search.
- Loading branch information
Showing
4 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const ALL_DOMAINS = ""; | ||
|
||
/** | ||
* Enhance the domain filter to include a subdomain input in addition | ||
* to the domain filter. When a domain is selected, the widget should | ||
* dynamically populate the subdomain options, and when a domain is | ||
* cleared, the subdomain should be cleared too. | ||
* | ||
* Note: This widget does not automatically refresh the results - the user | ||
* has to hit "Apply filters" first. | ||
*/ | ||
export const initDomainFilter = function () { | ||
const subdomainFilter = document.querySelector("#subdomains-filter"); | ||
const domainFilter = document.querySelector("#domains-filter"); | ||
|
||
if (subdomainFilter === null || domainFilter === null) { | ||
return; | ||
} | ||
|
||
// TODO interact with selected filters widget | ||
// we need to be able to add and remove entries from this dynamically | ||
|
||
const checkDomainSelected = function () { | ||
const selectedOptions = Array.from(domainFilter.selectedOptions); | ||
|
||
if ( | ||
selectedOptions.length === 0 || | ||
selectedOptions.some((el) => el.value != ALL_DOMAINS) | ||
) { | ||
onSelectParentDomain(); | ||
} else { | ||
onClearDomain(); | ||
} | ||
}; | ||
|
||
const onSelectParentDomain = function () { | ||
console.log("Selected domain"); | ||
|
||
subdomainFilter.setAttribute("disabled", false); | ||
|
||
// TODO populate subdomain options based on selected parent domain | ||
}; | ||
|
||
const onClearDomain = function () { | ||
console.log("Cleared domain"); | ||
|
||
subdomainFilter.setAttribute("disabled", true); | ||
|
||
// TODO remove subdomain options | ||
}; | ||
|
||
checkDomainSelected(); | ||
// TODO: Set up event handlers | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters