Skip to content

Commit

Permalink
feat: Remove 'unique' property from List schema (QuestionField) (#3331
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DafyddLlyr authored Jun 28, 2024
1 parent f7410aa commit e873e11
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 15 deletions.
13 changes: 0 additions & 13 deletions editor.planx.uk/src/@planx/components/List/Public/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ export const SelectFieldInput: React.FC<Props<QuestionField>> = (props) => {
const { formik, activeIndex } = useListContext();
const { id, data } = props;

const isDisabled = (option: Option) => {
if (!props.unique) return false;

const existingValues = formik.values.userData
.map((response) => response[data.fn])
.filter(
(value) => value === option.data.val || value === option.data.text,
);

return existingValues.includes(option.data.val || option.data.text);
};

return (
<InputLabel
label={data.title}
Expand All @@ -186,7 +174,6 @@ export const SelectFieldInput: React.FC<Props<QuestionField>> = (props) => {
<MenuItem
key={option.id}
value={option.data.val || option.data.text}
disabled={isDisabled(option)}
>
{option.data.text}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ describe("Form validation and error handling", () => {
test.todo("text fields use existing validation schemas");
test.todo("number fields use existing validation schemas");
test.todo("question fields use validation schema");
test.todo("unique constraints are enforced on question where this is set");
test.todo("an error displays if the minimum number of items is not met");
test.todo("an error displays if the maximum number of items is exceeded");
test.todo(
Expand Down
1 change: 0 additions & 1 deletion editor.planx.uk/src/@planx/components/List/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type NumberField = {

export type QuestionField = {
type: "question";
unique?: boolean;
data: QuestionInput & { fn: string };
};

Expand Down

0 comments on commit e873e11

Please sign in to comment.