question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow handling of non-native inputs

See original GitHub issue

🚀 Feature request

It should be possible to handle inputs, which are not backed by native input (input, textarea, select).

Current Behavior

Both formik 1.5.x and 2.x define:

// excerpt interface FormikHandlers
interface FormikHandlers {
  /** Classic React change handler, keyed by input name */
  handleChange(e: React.ChangeEvent<any>): void;
  /** Preact-like linkState. Will return a handleChange function.  */
  handleChange<T = string | React.ChangeEvent<any>>(
    field: T
  ): T extends React.ChangeEvent<any>
    ? void
    : ((e: string | React.ChangeEvent<any>) => void);
}

This requires me to either provide signal in preact linkstate style or as native dom change event. I can not create a pure JS element without linkstate or native dom input, which simply notifies value change passing it to onChange (aka handleChange API).

Desired Behavior

It should be possible to notify onChange with pure updated value.

Suggested Solution

Typing: AFAIK it can be tricky to make this BC to preact API, because of the T generic part in :

interface FormikHandlers {
  handleChange<T = string | React.ChangeEvent<any>>(
    field: T
  ): T extends React.ChangeEvent<any>
    ? void
    : ((e: string | React.ChangeEvent<any>) => void);
}
  1. add overload like this:
interface FormikHandlers {
  handleChange<T>(value: T, pure: true): void;
}
  1. or this:
interface FormikHandlers {
  handleChange<T>(data: {value: T, field: string}): void;
}

Here, the T generic is not needed, however not sure due to the other overloads if it is valid to omit it.

Runtime:

  1. Similar, checking the second argument (boolean) to handle the pure value case.
  2. check for {value, field} structure.

Who does this impact? Who is this for?

Evenryone who wants to create a pure JS input, which is not backed by DOM and does not want to use linkstate.

Describe alternatives you’ve considered

There is a solution to this I missed? Checked docs and code for both 1.5.x and 2.x and could not find any…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12

github_iconTop GitHub Comments

1reaction
akommcommented, Apr 23, 2020

Going to close this, as the feature is being on a PR currently and there is a workaround until its up. Thanks.

0reactions
akommcommented, Apr 23, 2020

@johnrom thanks. It works. Btw. I had to setFieldTouched before setFieldValue, otherwise the errors would reset. Not sure if it is a desired behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comprehending non-native speakers: theory and evidence for ...
We suggest that expectations of lower competence lead listeners to adapt their manner of processing when they listen to non-native speakers.
Read more >
Invasive Species Can Sometimes Help an Ecosystem
Can nonnative species, which are often regarded as invasive pests by ... Without management of nonnative plants, a rewilding approach could ...
Read more >
Handling common accessibility problems - MDN Web Docs
Let's look at an example, using Wave. Go to the Wave homepage. Enter the URL of our bad-semantics.html example into the text input...
Read more >
Comprehending non-native speakers: theory and ... - NCBI
Non-native speakers have lower linguistic competence than native speakers, which renders their language less reliable in conveying their intentions.
Read more >
Non-native Invasive Species Best Management Practices
Elements of Non-native Invasive Species Management . ... impacts of allowing NNIS to spread and the economic realities of control measures. Not all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found