-
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,7 @@ GEMINI.md | |
|
|
||
| .claude/worktrees | ||
| .claude/settings.local.json | ||
| .claude/skills | ||
| .opensource | ||
|
|
||
| # Polaris | ||
|
|
||
| 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.value === 'checked'); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Verify checkbox event handling in similar components
# Search for other checkbox change event handlers in the codebase
rg -n -A3 -B3 "addEventListener\s*\(\s*['\"]change['\"]" --glob "*.ts" --glob "*.js" -g '!node_modules'Repository: ForgeRock/ping-javascript-sdk Length of output: 7149 🏁 Script executed: cat -n e2e/davinci-app/components/boolean.tsRepository: ForgeRock/ping-javascript-sdk Length of output: 2558 Use The checkbox Proposed fix checkbox.addEventListener('change', (event) => {
const target = event.target as HTMLInputElement;
- updater(target.value === 'checked');
+ updater(target.checked);
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| wrapper.appendChild(checkbox); | ||||||||||||||||||
| wrapper.appendChild(label); | ||||||||||||||||||
| containerDiv.appendChild(wrapper); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Append the container to the form | ||||||||||||||||||
| formEl.appendChild(containerDiv); | ||||||||||||||||||
| } | ||||||||||||||||||
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