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

feat: Remove 'unique' property from List schema (QuestionField) #3331

Merged
merged 1 commit into from
Jun 28, 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
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
Loading