Skip to content

Commit

Permalink
feat: Remove 'unique' property from List schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jun 27, 2024
1 parent 91784c2 commit 7c5d743
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 @@ -154,18 +154,6 @@ export const SelectFieldInput: React.FC<Props<QuestionField>> = (props) => {
const { formik, activeIndex } = useListContext();
const { id, data, required } = 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={required === false ? data.title + " (optional)" : data.title}
Expand All @@ -188,7 +176,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("optional fields can be empty when saving an item");
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");
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 @@ -42,7 +42,6 @@ export type NumberField = {
export type QuestionField = {
type: "question";
required?: boolean;
unique?: boolean;
data: QuestionInput & { fn: string };
};

Expand Down

0 comments on commit 7c5d743

Please sign in to comment.