Repository navigation
[form][field] Add actionsRef - #3395
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
2daaef3 to
13eedca
Compare
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
cb13f43 to
40c2427
Compare
40c2427 to
1495f85
Compare
b28194e to
ec56855
Compare
LukasTy
left a comment
There was a problem hiding this comment.
LGTM, nice addition. 👍
I've changed the label to new feature instead of enhancement. 🙈
| const values = Array.from(formRef.current.fields.values()); | ||
|
|
||
| if (fieldName) { | ||
| const namedField = values.find((field) => field.name === fieldName); | ||
| if (namedField) { | ||
| namedField.validate(false); | ||
| } | ||
| } else { | ||
| values.forEach((field) => { |
There was a problem hiding this comment.
Looks slightly more efficient.
| const values = Array.from(formRef.current.fields.values()); | |
| if (fieldName) { | |
| const namedField = values.find((field) => field.name === fieldName); | |
| if (namedField) { | |
| namedField.validate(false); | |
| } | |
| } else { | |
| values.forEach((field) => { | |
| if (fieldName) { | |
| const namedField = formRef.current.fields.get(fieldName); | |
| if (namedField) { | |
| namedField.validate(false); | |
| } | |
| } else { | |
| Array.from(formRef.current.fields.values()).forEach((field) => { |
There was a problem hiding this comment.
Gotta do it like this because the map key is the id and not the field name 😬
There was a problem hiding this comment.
Gotcha.
Well, then maybe move the L74 to be inline in L82 to avoid unnecessary calculations in case they are not needed? 🤔
There was a problem hiding this comment.
We need the array in the if as well to do a .find() on it for the field name ~
There was a problem hiding this comment.
Oh yes, silly me. Sorry for causing commotion here. 🙈
Regardless, it would be nice to have access to the field ID here to improve the performance and simplicity of the code.
With |
Adds a
actionsRef.validatemethod to Form and Field so validation can be called imperatively (and arbitrarily).Form:
Field:
Closes #3323