-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can clicking the custom "I want to submit" button not trigger the onsubmit event of the form? #2617
Comments
Can clicking the custom "I want to submit" button not trigger the onsubmit event of the form? Code above |
Where is your code for the "I want to submit" button? |
import React from 'react'; import Input from '@c/input'; import { FormInput } from '@c/form-schema'; function LoginLockForm(): JSX.Element { const widgets = { const uiSchema = { 'ui:field': 'password' }; const fields = { function customSubmit(): void { function validate(formData: any, errors: any): any { const onSubmit = ({ formData }: any) => console.log('Data submitted: ', formData); return ( <Form ref={(form) => { console.log(form); yourForm = form; }} schema={schema} // uiSchema={uiSchema} // fields={fields} widgets={widgets} validate={validate} FieldTemplate={CustomFieldTemplate} onSubmit={onSubmit} noHtml5Validate > {/* <React.Fragment /> /} {/ <div style={{ display: 'none' }}> I want to Submit ); } export default LoginLockForm; function PasswdFunc(props: any): JSX.Element { function handleChange(value: boolean | string, key: string): void { return ( <input type="checkbox" onChange={(e) => handleChange(e.target.checked, 'isTrue')} /> 连续输错密码 <Input onChange={(value) => { console.log(value); handleChange(value, 'passwdLimit'); }} /> 次后,锁定该账户 <Input onChange={(value) => handleChange(value, 'lockLimit')} /> 分钟 ); } function IpValidate(): JSX.Element { 同一 IP 连续登录失败 次后,锁定该账户 分钟 ); } function CustomFieldTemplate(props: any): JSX.Element { {children} ); } return ( <div style={{ width: '186px', textAlign: 'left' }}> {label}{required ? '' : null} {/ {description} /} {id === 'root_password' && <PasswdFunc {...props} />} {id === 'root_ip' && <IpValidate {...props} />} {/ {rawErrors && rawErrors[0]} {help} */} ); } |
Please look at the above code. Why can't onsubmit be triggered |
You should wrap it in a |
If it can only be placed in the children of the form, it has great limitations and cannot be satisfied. I want to call the submitted scenario externally, so this problem should be improved and optimized. |
That would be a duplicate of #500, then, please take a look at that issue |
Prerequisites
Description
Can clicking the custom "I want to submit" button not trigger the onsubmit event of the form
[Description of the bug or feature]
Steps to Reproduce
function LoginLockForm(): JSX.Element {
let yourForm: any;
const schema: any = {
type: 'object',
properties: {
password: {
type: 'object',
title: '密码验证',
},
ip: { type: 'object', title: 'IP校验' },
},
required: ['password', 'ip'],
};
const widgets = {
TextWidget: FormInput,
};
const uiSchema = { 'ui:field': 'password' };
const fields = {
password: PasswdFunc,
ip: IpValidate,
};
function customSubmit(): void {
yourForm.submit();
console.log(yourForm);
// yourForm.submit();
}
function validate(formData: any, errors: any): any {
if (formData.password !== {}) {
errors.password.addError('Passwords don't match');
}
return errors;
}
const onSubmit = ({ formData }: any) => console.log('Data submitted: ', formData);
return (
<Form
ref={(form) => {
console.log(form);
yourForm = form;
}}
schema={schema}
// uiSchema={uiSchema}
// fields={fields}
widgets={widgets}
validate={validate}
// FieldTemplate={CustomFieldTemplate}
onSubmit={onSubmit}
noHtml5Validate
>
{/* <React.Fragment /> /}
{/ <div style={{ display: 'none' }}>
我要提交
);
}
Expected behavior
[What you expected to happen]
Actual behavior
[What actually happened]
Version
You can usually get this information in your
package.json
or in the file URL if you're using the unpkg one.The text was updated successfully, but these errors were encountered: