Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REACT ADMIN | TEXTINPUT CHANGE VALUE

how can I change the value of an TextInput in react-admin.

My idea was

<TextInput label="..." source="..." value="MY VALUE" />

But that doesn't work. pls help.

like image 576
Fynn Avatar asked Nov 18 '25 23:11

Fynn


1 Answers

You can't do this with the react-admin's TextInput as it is a connected field to the backing react-final-form form and hence you don't control the input.

You should state what is your final aim. I can think of two options:

  1. If you want to have a controlled input you can simply use material-ui's TextField and pass to it your custom value as well as handle the onChange event.

  2. If you don't want to control the value by yourself but alter it in the form state under some condition, you can then use the hook provided by react-final-form:

    const form = useForm();
    form.change("myValue", newValue);
    ...
    <TextInput label="My Value" source="myValue"  />
    
like image 179
Kia Kaha Avatar answered Nov 20 '25 12:11

Kia Kaha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!