import FormBuilder, { defaultProps, FormContext } from '@nozify/form-builder';
const schema = {
title: 'Todo',
type: 'object',
required: ['title'],
properties: {
title: { type: 'string', title: 'Title', default: 'A new task' },
done: { type: 'boolean', title: 'Done?', default: false },
},
};
const Form = () => {
const form: any = useRef<any>();
const onSubmit = (formData: any) => {};
return (
<FormContext.Provider
value={{
...defaultProps,
}}>
<ScrollView>
{schema && (
<FormBuilder
ref={form}
onError={(e) => {
console.log(e);
}}
schema={schema as any}
onSubmit={(f: any) => onSubmit(f.formData)}>
<Button
title="Save"
onPress={() => {
if (form.current) {
(form.current as any)?.submit();
}
}}
/>
</FormBuilder>
)}
</ScrollView>
</FormContext.Provider>
);
};