marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
25.01k stars 5.26k forks source link

Cannot pass a value to TextInput #4111

Closed jturge0n closed 4 years ago

jturge0n commented 4 years ago

I've been trying to utilize a search bar component that we've built to populate a inside a component.

The way I'd like to do this is declare a state variable, storeId, that gets updated when the user searches using our search bar and then selects an option.

I want to set the value of the to equal the storeId state variable such that when the stateId gets updated, the input value of the gets updated.

For whatever reason, it seems impossible to do this in any way. I've tried using options = {{ value: stateId }}

Can anyone tell me why the value input doesn't work to make a value equal to a local state variable?

Here's generally the code I have:

const [storeId, setStoreId] = useState(STORE_FILTER_ALL_STORES);
return (
   <StoreFilter
              storeId={storeId}
              onChange={setStoreId}
              permissions={permissions}
              allowedPermissions={ADMIN_PERMISSIONS.LIST_STORES}
              filter={{ active: true }}
              className={classes.searchField}
              label="Search Label"
            />

  <TextInput
              value={storeId}
              source="store_id"
              label="Store Number"
              required
            />
);

Environment

djhi commented 4 years ago

Hi, and thanks for your question.

Indeed, inputs and fields are not simple UI components and their values are populated by the framework from its datasource which depends on the context (Filter, List, Edit, etc.).

So first, we would need a lot more information to help you achieve what you want (which isn't clear) and second, this should happen on StackOverFlow as we only use Githug for tracking issues.

This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.

So I'm closing this issue, and inviting you to ask your question at:

http://stackoverflow.com/questions/tagged/react-admin

And once you get a response, please continue to hang out on the react-admin channel in StackOverflow. That way, you can help newcomers and share your expertise!