teslamotors / informed

A lightweight framework and utility for building powerful forms in React applications
https://teslamotors.github.io/informed
MIT License
951 stars 173 forks source link

React does not recognize the `validateOnBlur` prop on a DOM element #235

Closed RyanWarner closed 5 years ago

RyanWarner commented 5 years ago

Hello and thank you for the great library.

I'm using BasicText with the asField HOC and I'm getting some warnings in the console about props being set on the input DOM element.

Could this be solved by pulling these props off, like is being done here https://github.com/joepuzzo/informed/blob/master/src/components/form-fields/Text.js#L10 before passing the rest to the input? Or is this a user error on my part?

react-dom.development.js:506 Warning: React does not recognize the `validateOnBlur` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `validateonblur` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Warning: Invalid value for prop `validate` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM.
RyanWarner commented 5 years ago

Of course, 5 minutes after posting an issue, I fix my issue.

What I was doing:

export default asField(({ options, ...props }) => {
  const { label } = options
  const { error } = props.fieldState

  return <S.InputWrap>
    { label && <S.Label>{label}</S.Label> }
    <S.TextInput {...props} {...options} />
    <S.Error>{error}</S.Error>
  </S.InputWrap>
})

<TextField options={options} />

What fixed it:

<TextField {...options} />

And in the TextInput component <S.TextInput {...props} />