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: properly handle all formats of options sources #963

Merged
merged 1 commit into from
Jan 3, 2024
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
110 changes: 77 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/form-js-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"feelin": "^3.0.0",
"flatpickr": "^4.6.13",
"ids": "^1.0.0",
"lodash.isequal": "^4.5.0",
"min-dash": "^4.0.0",
"preact": "^10.5.14",
"preact-markup": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { useRef } from 'preact/hooks';
import useOptionsAsync, { LOAD_STATES } from '../../hooks/useOptionsAsync';
import useCleanupMultiSelectValues from '../../hooks/useCleanupMultiSelectValues';
import classNames from 'classnames';
import isEqual from 'lodash/isEqual';

import Description from '../Description';
import Errors from '../Errors';
import Label from '../Label';

import { sanitizeMultiSelectValue } from '../util/sanitizerUtil';
import { sanitizeMultiSelectValue, hasEqualValue } from '../util/sanitizerUtil';

import { createEmptyOptions } from '../util/optionsUtil';

Expand Down Expand Up @@ -41,19 +42,15 @@ export default function Checklist(props) {

const { required } = validate;

const toggleCheckbox = (v) => {
const toggleCheckbox = (toggledValue) => {

let newValue = [ ...values ];

if (!newValue.includes(v)) {
newValue.push(v);
} else {
newValue = newValue.filter(x => x != v);
}
const newValues = hasEqualValue(toggledValue, values)
? values.filter(value => !isEqual(value, toggledValue))
: [ ...values, toggledValue ];

props.onChange({
field,
value: newValue,
value: newValues,
});
};

Expand Down Expand Up @@ -96,17 +93,18 @@ export default function Checklist(props) {
loadState == LOAD_STATES.LOADED && options.map((o, index) => {

const itemDomId = `${domId}-${index}`;
const isChecked = hasEqualValue(o.value, values);

return (
<Label
id={ itemDomId }
label={ o.label }
class={ classNames({
'fjs-checked': values.includes(o.value)
'fjs-checked': isChecked
}) }
required={ false }>
<input
checked={ values.includes(o.value) }
checked={ isChecked }
class="fjs-input"
disabled={ disabled }
readOnly={ readonly }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRef } from 'preact/hooks';
import isEqual from 'lodash/isEqual';
import useOptionsAsync, { LOAD_STATES } from '../../hooks/useOptionsAsync';
import useCleanupSingleSelectValue from '../../hooks/useCleanupSingleSelectValue';
import classNames from 'classnames';
Expand Down Expand Up @@ -85,16 +86,17 @@ export default function Radio(props) {
loadState == LOAD_STATES.LOADED && options.map((option, index) => {

const itemDomId = `${domId}-${index}`;
const isChecked = isEqual(option.value, value);

return (
<Label
id={ itemDomId }
key={ index }
label={ option.label }
class={ classNames({ 'fjs-checked': option.value === value }) }
class={ classNames({ 'fjs-checked': isChecked }) }
required={ false }>
<input
checked={ option.value === value }
checked={ isChecked }
class="fjs-input"
disabled={ disabled }
readOnly={ readonly }
Expand Down
Loading
Loading