-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
onChange event for TextField with Select options does not include field name #9157
Comments
|
@gnapse The event of the onChange callback is coming from a click event. The target is not supposed to have a name attribute. As far as I'm concerned, the current behavior is the expected one. I understand your simplification use case, but I don't see how it could be handled by Material-UI core. Notice that your expected behavior is the current behavior of the native mode of the Select. @mbrookes Is right. I should have added the |
@oliviertassinari ok, I get now that using the native select it will work as I expect, and therefore I'll be using that. But just to be clear, for the other case, are you saying this does not need to be fixed? If the same component, |
@gnapse I'm saying that the documentation needs to be improved.
Yes, it's. I wish we could fix it, but I don't see how. It's structural to not using a native select. |
Oh wait, I have forgotten that we are already playing with 🔥 with the |
Good to know. In any case I'm leaning to always using these TextField-with-options as a native select. It integrates better with mobile, and now also this event signature mismatch compared to normal form input fields. But I'm happy if this is eventually fixable and fixed. |
@oliviertassinari I was mistaken about I'd still like to know what the plan is for standardizing the ordering of the callback signature. It's a shame @alitaheri's proposal (#2957) wasn't implemented from the start for v1... but it isn't too late! |
@mbrookes I'm not sure to understand your point about standardizing the callbacks arguments. I have tried to make them as standard as possible so far. Do you see some issues? |
@oliviertassinari I hadn't noticed that we're adding children to the event to propagate additional attributes, rather than passing multiple args to the callback function. That's smart. 😄 I guess it might be helpful to document those? |
@mbrookes I'm not sure how we can improve the docs. If you see, go ahead :). I have submitted a PR to add the |
On a regular
TextField
, theonChange
event handler receives an event parameter that allows to know the name of theTextField
as well as the value that was changed to:However, on a
TextField
with nested options, which renders internally aSelect
, this is no longer the case. The element given astarget
in theonChange
event is theli
of the dropdown list, which only has avalue
, but noname
.Expected Behavior
The
onChange
event handler of a<TextField name="xyz">{options}</TextField>
should receive an event object whereevent.target.name
is"xyz"
.Current Behavior
The
onChange
event handler of a<TextField name="xyz">{options}</TextField>
receives an event object whereevent.target.name
isundefined
.Steps to Reproduce (for bugs)
Context
Having the name reflected in the event target is not only more compatible with how actual form input events work in html, it is also convenient because you can use the same onChange event handler for many input elements, instead of dynamically having to generate a different event handler for different input elements of a form.
Your Environment
The text was updated successfully, but these errors were encountered: