Skip to content

Instantly share code, notes, and snippets.

@Cloudo
Created August 5, 2020 09:37
Show Gist options
  • Save Cloudo/65c33c801fca701ce355bc5f9bc475b5 to your computer and use it in GitHub Desktop.
Save Cloudo/65c33c801fca701ce355bc5f9bc475b5 to your computer and use it in GitHub Desktop.
export const schemaThirdStepPoll = Yup.object().shape<Partial<PollOrOssParams>>({
questions: Yup.array()
.ensure()
.of(
// @ts-ignore
Yup.lazy<any>((item, options) => {
const itemIndex = options.parent.indexOf ? options.parent.indexOf(item) : -1;
let description = Yup.string().min(50);
if (itemIndex > 0) {
description = description.required();
}
return Yup.object().shape({
text: Yup.string().required().min(20),
type: Yup.string().required(),
description,
answers: Yup.array()
.ensure()
.of(
Yup.object().shape({
answer: Yup.string().required(),
})
),
});
})
),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment