Field name cannot be a number
See original GitHub issueI am trying to set a Field
’s name prop as a number (e.g. <Field name="123" component="input" />
).
The problem is that when the fields
key in state is created, instead of creating an object with the key “123”, it creates an array with a length of 124, filled with nulls except the last index.
The issue I believe is that the setIn
function, which is what creates the state, does not differentiate between dot and bracket syntax. If it sees a number, it creates an array. So even though it is being called as setIn(result, 'fields.123.visited', true)
, it is being considered as setIn(result, 'fields[123].visited', true)
.
The solution would probably be to have this function account for whether or not dot notation was used when encountering a number. The other solution would be to just not use numbers as names, but I feel that since this is valid in the DOM, it should be able to be done here as well.
I already wrote a failing test, but don’t have a working solution yet.
I’m curious to know if I am understanding the problem correctly, and if this functionality is something that should be supported.
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
I just spent an hour investigating this.
In
v5
, I had quite a bit of code that was parsing the dot-vs-bracket notation, and it was a veritable mess, and a source of very many bugs. It was a very conscious decision to switch to use_.toPath()
inv6
to avoid that headache.So I think the answer is that numeric field names are not supported. Prefix it with something. e.g.
'field_123'
.If you wrote a very thoroughly tested implementation of
setIn
, for both plain and immutable structures, I might consider a change of this policy.This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.