koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

How to clear extraneous properties from v-model when switching schemas dynamically #435

Closed Q16solver closed 1 month ago

Q16solver commented 1 month ago

I currently have an editor that has a type field, and various schemas that get switched around based on this type https://github.com/Esposter/Esposter/blob/main/packages/app/components/Dashboard/Visual/Preview/EditFormDialog.vue

However, when the schemas are switched, the data in my v-model is kept. I want this behaviour for common properties between the schemas, but I want to clear out the properties that aren't common, as when I save in the editor, I will have a validator that checks the data against the new schema, and it would not pass it, is there a way to nicely clean out the extra properties that aren't a part of the vjsf schema?

albanm commented 1 month ago

This is controlled by the removeAdditional option. The default mode is "error" meaning that additional properties will be removed only if they trigger validation errors (so if you have additionalProperties=false in your schema). So you can either had this to your schema where relevant or you can use removeAdditional=true to remove all additional properties.

Q16solver commented 1 month ago

Sweet! That's exactly what I needed, thanks so much! closing this issue now