-
Notifications
You must be signed in to change notification settings - Fork 3
feat(davinci-client): support single checkbox component #629
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
Open
ancheetah
wants to merge
2
commits into
main
Choose a base branch
from
SDKS-4926-single-checkbox
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,11 @@ | ||
| --- | ||
| '@forgerock/davinci-client': minor | ||
| --- | ||
|
|
||
| Adds support for the SINGLE_CHECKBOX field. A new ValidatedBooleanCollector type was introduced including validation support for required checkboxes and updater support for booleans. | ||
|
|
||
| **Type improvements** | ||
|
|
||
| - `SingleValueCollectorWithValue<T, V>` and `ValidatedSingleValueCollectorWithValue<T, V>` are now generic over their value type (`V`, defaults to `string`), replacing the loose `string | number | boolean` union | ||
|
|
||
| - `Validator` is now generic over collector type `T`, replacing the hardcoded `string` input with `CollectorValueType<T>` — so validators receive the value type that matches their collector (e.g. `boolean` for `ValidatedBooleanCollector`, `string` for text collectors) rather than always `string` |
This file contains hidden or 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 hidden or 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,57 @@ | ||
| /* | ||
| * Copyright (c) 2026 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import type { ValidatedBooleanCollector, Updater } from '@forgerock/davinci-client/types'; | ||
|
|
||
| /** | ||
| * Creates a single checkbox and attaches it to the form | ||
| * @param {HTMLFormElement} formEl - The form element to attach the checkboxes to | ||
| * @param {ValidatedBooleanCollector} collector - Contains the configuration | ||
| * @param {Updater} updater - Function to call when selection changes | ||
| */ | ||
| export default function booleanComponent( | ||
| formEl: HTMLFormElement, | ||
| collector: ValidatedBooleanCollector, | ||
| updater: Updater<ValidatedBooleanCollector>, | ||
| ) { | ||
| // Create a container for the checkboxes | ||
| const containerDiv = document.createElement('div'); | ||
| containerDiv.className = 'single-checkbox-container'; | ||
|
|
||
| // Create a heading/label for the checkbox group | ||
| const groupLabel = document.createElement('div'); | ||
| groupLabel.textContent = collector.output.label || 'Single Checkbox'; | ||
| groupLabel.className = 'single-checkbox-label'; | ||
| containerDiv.appendChild(groupLabel); | ||
|
|
||
| // Create checkboxes for each option | ||
| const wrapper = document.createElement('div'); | ||
| wrapper.className = 'checkbox-wrapper'; | ||
|
|
||
| const checkbox = document.createElement('input'); | ||
| checkbox.type = 'checkbox'; | ||
| checkbox.id = collector.output.key; | ||
| checkbox.name = collector.output.key || 'single-checkbox-field'; | ||
| checkbox.checked = collector.output.value; | ||
| checkbox.value = 'checked'; | ||
|
|
||
| const label = document.createElement('label'); | ||
| label.htmlFor = checkbox.id; | ||
| label.textContent = collector.output.label; | ||
|
|
||
| // Add event listener to handle single-select behavior | ||
| checkbox.addEventListener('change', (event) => { | ||
| const target = event.target as HTMLInputElement; | ||
| updater(target.checked); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| wrapper.appendChild(checkbox); | ||
| wrapper.appendChild(label); | ||
| containerDiv.appendChild(wrapper); | ||
|
|
||
| // Append the container to the form | ||
| formEl.appendChild(containerDiv); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Consider adding
requiredattribute support.The
SingleCheckboxFieldtype includes arequiredproperty, but the component doesn't set the HTMLrequiredattribute on the checkbox element. This means required validation won't work as expected.🛡️ Proposed fix
const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.id = collector.output.key; checkbox.name = collector.output.key || 'single-checkbox-field'; checkbox.checked = collector.output.value as boolean; checkbox.value = 'checked'; + if (collector.output.required) { + checkbox.required = true; + }📝 Committable suggestion
🤖 Prompt for AI Agents