Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getFormFromSchema (
schema: JSONSchema7,
onSubmit: Config['onSubmit'],
initialValues = {} // tslint:disable-line typedef
): FormApi {
const form = createForm({
validate: validateWithSchema(schema),
onSubmit,
initialValues
});
registerFields(form, schema);
return form;
}
klass.__initializers.push(self => {
Object.assign(self, {
// Fields
[$formApi]: createForm(
formOptionResponsibilityKeys.reduce((acc, key) => {
if (sharedProperties[key]) {
acc[key] = self[sharedProperties[key]];
}
return acc;
}, {}),
),
// eslint-disable-next-line sort-keys
[$$unsubscriptions]: [],
// Methods
// eslint-disable-next-line sort-keys
[$$reset](event) {
event.preventDefault();
event.stopPropagation();
constructor(props: Props<data>) {
super(props);
const { initialValues, subscriptions } = props;
// Setup our form instance
this.form = createForm<data>({
destroyOnUnregister: true,
initialValues,
mutators: {
setFieldConfig: this.setFieldConfig,
},
onSubmit: this.handleSubmit,
validate: this.handleValidate,
});
this.form.subscribe(this.handleStateUpdate, mapSubscriptions(subscriptions as string[]));
// Wait until mounted
this.form.pauseValidation();
}
</data></data>
constructor() {
super()
const initialState = {}
let inConstructor = true
this.form = createForm({ onSubmit })
// subscribe to form changes
this.unsubscribe = this.form.subscribe(
formState => {
// cannot call setState in constructor, but need to on subsequent notifications
if (inConstructor) {
initialState.formState = formState
} else {
this.setState({ formState })
}
},
{ active: true, pristine: true, submitting: true, values: true }
)
// register fields
this.unsubscribeFields = ['firstName', 'lastName'].map(fieldName =>
const form: FormApi = useConstant(() => {
const f = alternateFormApi || createForm(config)
// pause validation until children register all fields on first render (unpaused in useEffect() below)
f.pauseValidation()
return f
})
constructor({ id, label, fields, actions, ...options }: FormOptions<s>) {
this.id = id
this.label = label
this.fields = fields
this.finalForm = createForm<s>({
...options,
async onSubmit(values, form, cb) {
let response = await options.onSubmit(values, form, cb)
form.initialize(values)
return response
},
mutators: {
...arrayMutators,
...options.mutators,
},
})
/**
* We register fields at creation time so we don't have to relay
* on `react-final-form` components being rendered.
*/
this.registerFields(this.fields)</s></s>
const form = useMemoOnce(() => createForm(config))
const prevConfig = useRef(config)
data() {
return {
finalForm: createForm({
onSubmit: this.submit,
initialValues: this.initialValues,
validate: Array.isArray(this.validate) ? composeFormValidators(this.validate) : this.validate
}),
formState: null
}
},