-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure values not in options clear
Closes #817
- Loading branch information
Showing
7 changed files
with
111 additions
and
3 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
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
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
32 changes: 32 additions & 0 deletions
32
packages/form-js-viewer/src/render/hooks/useRestrictedMultiSelectValues.js
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,32 @@ | ||
import { useEffect } from 'preact/hooks'; | ||
import { LOAD_STATES } from './useOptionsAsync'; | ||
|
||
export default function(props) { | ||
|
||
const { | ||
field, | ||
options, | ||
loadState, | ||
onChange, | ||
values | ||
} = props; | ||
|
||
// Ensures that the values are always a subset of the options | ||
useEffect(() => { | ||
|
||
if (loadState !== LOAD_STATES.LOADED) { | ||
return; | ||
} | ||
|
||
const hasValuesNotInOptions = values.some(v => !options.map(o => o.value).includes(v)); | ||
|
||
if (hasValuesNotInOptions) { | ||
onChange({ | ||
field, | ||
value: values.filter(v => options.map(o => o.value).includes(v)) | ||
}); | ||
} | ||
|
||
}, [ field, options, onChange, JSON.stringify(values), loadState ]); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
packages/form-js-viewer/src/render/hooks/useRestrictedSingleSelectValue.js
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,31 @@ | ||
import { useEffect } from 'preact/hooks'; | ||
import { LOAD_STATES } from './useOptionsAsync'; | ||
|
||
export default function(props) { | ||
|
||
const { | ||
field, | ||
options, | ||
loadState, | ||
onChange, | ||
value | ||
} = props; | ||
|
||
useEffect(() => { | ||
|
||
if (loadState !== LOAD_STATES.LOADED) { | ||
return; | ||
} | ||
|
||
const hasValueNotInOptions = value && !options.map(o => o.value).includes(value); | ||
|
||
if (hasValueNotInOptions) { | ||
onChange({ | ||
field, | ||
value: null | ||
}); | ||
} | ||
|
||
}, [ field, options, onChange, value, loadState ]); | ||
|
||
} |