-
-
Notifications
You must be signed in to change notification settings - Fork 50.8k
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
Disable submit button on form #4374
Comments
It can be done by passing disabled to |
So.. we need to find |
What we need is a handy API to determine whether all |
|
Hi guys, So if I understand, you'll work on it ? |
We need a |
To achieve the new target. We need to add But the problem is that, |
But I think that we can add this feature, thought there is a little breaking changes. |
rc-form add new feature:
|
You can do this thing in |
Thanks @benjycui ! |
Thanks @benjycui !! |
Hi @benjycui , instead of doing the stuff below manually:
how about adding an extra prop for form item like |
Nope, it's impossible to integrate all the UX logic in antd's components, so just customize with code. |
fair enough. Anyway, I created an HOC component to implement this, just in case anyone needs it: import React from 'react';
import PropTypes from 'prop-types';
import { Form } from 'antd';
const FormItem = Form.Item;
export default function EnhancedFormItem(
{ fieldName, showErrorOnlyTouched, neverShowError, ...props }, { form }) {
if (neverShowError) {
return (<FormItem
{...props}
help=""
validateStatus="" />);
}
if (showErrorOnlyTouched) {
const { getFieldError, isFieldTouched } = form;
const isTouched = isFieldTouched(fieldName);
const fieldError = getFieldError(fieldName);
const shouldShowError = isTouched && !!fieldError;
return (<FormItem
{...props}
help={shouldShowError ? fieldError : ''}
validateStatus={shouldShowError ? 'error' : ''} />);
}
return <FormItem {...props} />;
}
EnhancedFormItem.propTypes = {
fieldName: PropTypes.string,
showErrorOnlyTouched: PropTypes.bool,
neverShowError: PropTypes.bool,
};
EnhancedFormItem.contextTypes = {
form: PropTypes.object,
}; |
Hi @benjycui in the context, there is no form property after upgrading to antd3-rc3, is there any way to access form in the above solution (EnhancedFormItem) except passing it as a prop? |
@Kamahl19 |
@benjycui: Im using ant design with typescript, and demo code at line 47 in f436b5c fails in Typescript with following error message:
If I use |
Hi @benjycui why |
This is somewhat old bbut I found an official example in the login form in the docs to get this https://ant.design/components/form/#components-form-demo-normal-login |
Hi guys,
It is possible to disable the form button when all ForItem are not valided ?
Like react-validation does.
Thanks.
The text was updated successfully, but these errors were encountered: