Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to use global validator for useFieldArray #5000

rogerluo410 started this conversation in General
Discussion options

Use global validator, not yup, how to validate the object's attribute in the list,

 <tr v-for="(option, index) of editQuestionParamOptions" :key="index">
 <td :class="errors[`options.${index}.name`] ? 'is_error' : ''">
 <input
 v-model="(option.value as OptionProps).name"
 :disabled="disabled()"
 type="text"
 name="option test"
 @change="checkOptions()"
 />
 <p v-show="errors[`options.${index}.name`]" class="m_form_error">
 {{ errors[`options.${index}.name`] }}
 </p>
 </td>
 </tr>
 
 const { errors, resetForm, validate, setFieldValue } = useForm({
 validationSchema: {
 name: "required|max:255|first_deny:*,Q|string_deny:[,]|comma_deny",
 options: {
 name: "required|max:255|string_deny::"
 }
 }
 });
 
 const { value: editQuestionParamNameValue } = useField<string>("name");
 const {
 remove: optionRemove,
 push: optionAdd,
 fields: editQuestionParamOptions,
 } = useFieldArray<OptionProps>("options");

I want to set validationSchema like this, the options.name should be validated:

 validationSchema: {
 name: "required|max:255|first_deny:*,Q|string_deny:[,]|comma_deny",
 options: {
 name: "required|max:255|string_deny::"
 }
 }

But, not work. It throws out "Uncaught (in promise) Error: No such validator 'name' exists."

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /