-
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 as boolean; | ||||||||||||||||||
| 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); | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import type { | |
| InferActionCollectorType, | ||
| NoValueCollectorTypes, | ||
| InferNoValueCollectorType, | ||
| ValidatedBooleanCollector, | ||
| ValidatedSingleValueCollectorWithValue, | ||
| ValidatedTextCollector, | ||
| InferValueObjectCollectorType, | ||
|
|
@@ -45,6 +46,7 @@ import type { | |
| PollingField, | ||
| ReadOnlyField, | ||
| RedirectField, | ||
| SingleCheckboxField, | ||
| SingleSelectField, | ||
| StandardField, | ||
| ValidatedField, | ||
|
|
@@ -151,7 +153,7 @@ export function returnSubmitCollector(field: StandardField, idx: number) { | |
| * @returns {SingleValueCollector} The constructed SingleValueCollector object. | ||
| */ | ||
| export function returnSingleValueCollector< | ||
| Field extends StandardField | SingleSelectField | ValidatedField, | ||
| Field extends StandardField | SingleSelectField | ValidatedField | SingleCheckboxField, | ||
| CollectorType extends SingleValueCollectorTypes = 'SingleValueCollector', | ||
| >(field: Field, idx: number, collectorType: CollectorType, data?: string) { | ||
| let error = ''; | ||
|
|
@@ -212,10 +214,40 @@ export function returnSingleValueCollector< | |
| options: options, | ||
| }, | ||
| } as InferSingleValueCollectorType<'SingleSelectCollector'>; | ||
| } else if (collectorType === 'ValidatedBooleanCollector') { | ||
| const validationArray = []; | ||
| if ('required' in field && field.required === true) { | ||
| validationArray.push({ | ||
| type: 'required', | ||
| message: | ||
| ('validation' in field && field.validation?.errorMessage) || 'Value cannot be empty', | ||
| rule: true, | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| category: 'ValidatedSingleValueCollector', | ||
| error: error || null, | ||
| type: collectorType, | ||
| id: `${field.key}-${idx}`, | ||
| name: field.key, | ||
| input: { | ||
| key: field.key, | ||
| value: false, | ||
| type: field.type, | ||
| validation: validationArray, | ||
| }, | ||
| output: { | ||
| key: field.key, | ||
| label: field.label, | ||
| type: field.type, | ||
| value: false, | ||
| }, | ||
| } as ValidatedSingleValueCollectorWithValue<'ValidatedBooleanCollector'>; | ||
| } else if ('validation' in field || 'required' in field) { | ||
| const validationArray = []; | ||
|
|
||
| if ('validation' in field) { | ||
| if ('validation' in field && field.validation && 'regex' in field.validation) { | ||
|
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. Critical: Validation logic regression for required-only text fields. The condition on line 250 has been changed from: } else if ('validation' in field || 'required' in field) {to: } else if ('validation' in field && field.validation && 'regex' in field.validation) {This is a breaking change that affects existing functionality: Before: Text fields with either After: Only text fields with regex validation enter this branch. Text fields with only Impact: Required-only text fields will no longer be validated, which is a regression. Root cause: The change appears to be an unintended side effect of adding the 🔧 Proposed fixRestore the original OR logic to preserve validation for required-only fields: - } else if ('validation' in field && field.validation && 'regex' in field.validation) {
+ } else if ('validation' in field || 'required' in field) {
const validationArray = [];
if ('validation' in field && field.validation && 'regex' in field.validation) {The inner conditions at lines 250-256 and 257-263 already safely check for the presence of regex and required respectively, so the outer condition should use OR. 🤖 Prompt for AI Agents |
||
| validationArray.push({ | ||
| type: 'regex', | ||
| message: field.validation?.errorMessage || '', | ||
|
|
@@ -464,6 +496,16 @@ export function returnSingleSelectCollector(field: SingleSelectField, idx: numbe | |
| return returnSingleValueCollector(field, idx, 'SingleSelectCollector', data); | ||
| } | ||
|
|
||
| /** | ||
| * @function returnValidatedBooleanCollector - Creates a ValidatedBooleanCollector object based on the provided field and index. | ||
| * @param {SingleCheckboxField} field - The field object containing key, label, type, required, and validation. | ||
| * @param {number} idx - The index to be used in the id of the ValidatedBooleanCollector. | ||
| * @returns {ValidatedBooleanCollector} The constructed ValidatedBooleanCollector object. | ||
| */ | ||
| export function returnValidatedBooleanCollector(field: SingleCheckboxField, idx: number) { | ||
| return returnSingleValueCollector(field, idx, 'ValidatedBooleanCollector'); | ||
| } | ||
|
|
||
| /** | ||
| * @function returnProtectCollector - Creates a ProtectCollector object based on the provided field and index. | ||
| * @param {DaVinciField} field - The field object containing key, label, type, and links. | ||
|
|
@@ -846,7 +888,12 @@ export function returnAgreementCollector(field: AgreementField, idx: number): Ag | |
| * @returns {function} - A "validator" function that validates the input value | ||
| */ | ||
| export function returnValidator( | ||
| collector: ValidatedTextCollector | ObjectValueCollectors | MultiValueCollectors | AutoCollectors, | ||
| collector: | ||
| | ValidatedTextCollector | ||
| | ValidatedBooleanCollector | ||
| | ObjectValueCollectors | ||
| | MultiValueCollectors | ||
| | AutoCollectors, | ||
| ) { | ||
| const rules = collector.input.validation; | ||
| return (value: string | string[] | Record<string, unknown>) => { | ||
|
|
||
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