Skip to content
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

[Doc] Fix useInput documentation regarding errors display #9520

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/useInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Additional props are passed to [react-hook-form's `useController` hook](https://
```jsx
// in LatLongInput.js
import TextField from '@mui/material/TextField';
import { useInput, required } from 'react-admin';
import { useInput, required, InputHelperText } from 'react-admin';

const BoundedTextField = (props) => {
const { onChange, onBlur, label, ...rest } = props;
const { onChange, onBlur, label, helperText, ...rest } = props;
const {
field,
fieldState: { isTouched, invalid, error },
Expand All @@ -81,12 +81,22 @@ const BoundedTextField = (props) => {
{...field}
label={label}
error={(isTouched || isSubmitted) && invalid}
helperText={(isTouched || isSubmitted) && invalid ? error : ''}
helperText={helperText !== false || ((isTouched || isSubmitted) && invalid)
? (
<InputHelperText
touched={isTouched || isSubmitted}
error={error?.message}
helperText={helperText}
/>
)
: ''
}
required={isRequired}
{...rest}
/>
);
};

const LatLngInput = props => {
const { source, ...rest } = props;

Expand All @@ -99,6 +109,7 @@ const LatLngInput = props => {
);
};
```

## Usage with Material UI `<Select>`

```jsx
Expand Down
Loading