mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-10 09:22:34 +00:00
Convert to composition API
This commit is contained in:
parent
eaa03d8e72
commit
d2b191ed6e
8 changed files with 109 additions and 172 deletions
|
@ -13,7 +13,7 @@
|
|||
</Form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { isNotEmpty } from '@primeuix/utils';
|
||||
import { zodResolver } from '@primevue/form/resolvers';
|
||||
import { z } from 'zod';
|
||||
|
@ -23,43 +23,24 @@ import DynamicFormLabel from './DynamicFormLabel.vue';
|
|||
import DynamicFormMessage from './DynamicFormMessage.vue';
|
||||
import DynamicFormSubmit from './DynamicFormSubmit.vue';
|
||||
|
||||
export default {
|
||||
name: 'DynamicForm',
|
||||
emits: ['submit'],
|
||||
props: {
|
||||
fields: Object
|
||||
},
|
||||
provide() {
|
||||
return {
|
||||
$fcDynamicForm: this
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
defaultValues: {},
|
||||
schemas: {}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addField(name, schema, defaultValue) {
|
||||
schema && (this.schemas[name] = schema);
|
||||
this.defaultValues[name] = defaultValue;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
resolver() {
|
||||
return isNotEmpty(this.schemas) ? zodResolver(z.object(this.schemas)) : undefined;
|
||||
},
|
||||
initialValues() {
|
||||
return this.defaultValues;
|
||||
}
|
||||
},
|
||||
components: {
|
||||
DynamicFormControl,
|
||||
DynamicFormField,
|
||||
DynamicFormLabel,
|
||||
DynamicFormMessage,
|
||||
DynamicFormSubmit
|
||||
}
|
||||
const props = defineProps({
|
||||
fields: Object
|
||||
});
|
||||
|
||||
const emit = defineEmits(['submit']);
|
||||
|
||||
const defaultValues = ref({});
|
||||
const schemas = ref({});
|
||||
|
||||
const resolver = computed(() => (isNotEmpty(schemas.value) ? zodResolver(z.object(schemas.value)) : undefined));
|
||||
const initialValues = computed(() => defaultValues.value);
|
||||
|
||||
const addField = (name, schema, defaultValue) => {
|
||||
schema && (schemas.value[name] = schema);
|
||||
defaultValues.value[name] = defaultValue;
|
||||
};
|
||||
|
||||
provide('$fcDynamicForm', {
|
||||
addField
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue