Replies: 4 comments 4 replies
-
Ugh...... this entire thing is because I didn't notice I had
|
Beta Was this translation helpful? Give feedback.
-
Ok there is only one remaining issue that I'm not too sure about. Originally I thought it was a Yup issue not enforcing the The problem is vee says a form is valid when a nested field key is not present in the object. It DOES validate properly if the value is pre-filled in, or '', but not if its entirely missing. For example when a new object is created it looks like this:
Notice that This is problematic because veeValidate sees this as valid. For some reason I have to click into the input (which calls vee method This behavior click isn't required however when working with "normal" fields that are not nested, it immediately knows they're invalid. |
Beta Was this translation helpful? Give feedback.
-
More specifically it seems the input is showing Note that the other field shows
|
Beta Was this translation helpful? Give feedback.
-
I think this occurs when a schema dynamically changes and it's also nested. If I don't change the schema reactively (via API) then it seems to work. I can console.log the setup(props, { emit }) {
// originally property is {} empty, and comes in later as a prop when API resolves
const schemaFields = computed(() => (
Object.entries(props.property.schema.fields).map(([key, value]) => ({
id: key,
...value,
}))
));
const buildValidations = computed(() => {
const yupObject = schemaFields.value.reduce((acc, field) => {
// build validations like .string().required.label()
// ...
acc[field.id] = validation;
return acc;
}, {});
return object(yupObject);
});
// reactive schema
const validationSchema = computed(() => (
object({
name: string().required().label('Name'),
date: string().url().required().label('Date'),
fields: buildValidations.value,
})
));
// we specifically don't pass the .value so veeValidate knows to update
// the schema reactively
const { handleSubmit, meta } = useForm({
validationSchema,
}); |
Beta Was this translation helpful? Give feedback.
-
edit I solved the original problem below but there is another poblem i added in another reply, perhaps a bug?
I have a "dynamic form" where an arbitrary number of fields can be specified. This is posing a problem and I'm not quite sure how to get around it.
the "schema" model comes from the API (to tell the form what fields are to be added to the form/validated). It looks like this:
GET /schema/:id
Then we have the actual object which has a static portion (like a title), and the dynamic field portion. It looks like this (this is the actual object the user is editing)
My schema looks like this:
My "dynamic form" area looks like this:
The problem though is... I can't get it to actually validate.
I think the issue is that if I pass
validation-key
(this is what gets sent intouseInput
) which consists offield.someFieldId
its not reading it properly from the schema.If I try to pass simply
fields
then it actually SEES the validation but it says "undefined must be object" as if its looking at the outer fields and comparing it to the input modelValue which is a string.I have to make the model-value the actual value though (rather than the field), so I'm not sure how I can get both worlds
Beta Was this translation helpful? Give feedback.
All reactions