Skip to content
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

Why are the ...rest properties not included in input #10

Open
ackvf opened this issue Feb 22, 2019 · 4 comments
Open

Why are the ...rest properties not included in input #10

ackvf opened this issue Feb 22, 2019 · 4 comments

Comments

@ackvf
Copy link

ackvf commented Feb 22, 2019

One does not simply do this as usually:

<Field name="xTest" required type="number" render={({input}) => (
  return <input {...input}/>
)/>

It is now necessary to also pass ({input, ...rest}) to <input {...input} {...rest}/>, but careful, there also is the meta object!, so we must first consume it even though we don't need it. ({input, meta, ...rest})

image

I believe that it would make better sense to include all input props inside input property. If not, can you please shed some light on it and perhaps better documented in the example here? https://github.com/final-form/react-final-form-html5-validation

@erikras
Copy link
Member

erikras commented Feb 25, 2019

The reason is that this library is just a wrapper for Field, and Field, for good reason, keeps additional props out of the input object.

To accomplish what you're asking for would require React Final Form to provide some sort of optional inputProps interface where users could dump props that they want to end up inside input....which is a possibility.

@ackvf
Copy link
Author

ackvf commented Feb 25, 2019

I see!, so basically if I was to use the standard react-final-form Field in a same way as in the code above, the props required and type would -not- be included in the input prop as well?

Okay, that's an implementation detail I wasn't aware of, I thought that all input's applicable properties are passed in the input prop. Anyway, what you say makes perfect sense, thanks for clarification.

@TrejGun
Copy link

TrejGun commented Mar 12, 2019

it would be good to fix this

@ackvf
Copy link
Author

ackvf commented Apr 28, 2019

While investigating another issue, I discovered that required IS sometimes passed to the underlying DOM input element... I believe this isn't right, though I wish if it was sent.

required-field

https://codesandbox.io/s/wqrywv2lkw

<div>
  <label>Required Field*</label>
  <Field
    name="field2"
    component="input"
    type="text"
    required // is passed to dom input
  />
</div>

<Field name="field3" required>
  {({ input, meta }) => (
    <div>
      <label>Required Field*</label>
      <input
        {...input} // required is not inclued here
        type="text"
      />
      {meta.error && meta.touched && <span>{meta.error}</span>}
    </div>
  )}
</Field>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants