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.

[feature]not removing field name from state, when its value become empty

See original GitHub issue

In all examples if write something in input, than clear it, the field name will be dropped from state. But is it possibly maybe with some additional prop like notRemoveWhenEmpty in Field, the value will be null, or empty or anything else.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:42
  • Comments:24 (4 by maintainers)

github_iconTop GitHub Comments

43reactions
petermikitshcommented, Sep 28, 2018

In the meantime, I’ve wrote a simple adapter for the Field component, and my application code imports this adapter component in place of the official one:

import {Field} from 'react-final-form';
import React from 'react';

const identity = value => (value);

/* This wraps react-final-form's <Field/> component.
 * The identity function ensures form values never get set to null,
 * but rather, empty strings.
 *
 * See https://github.com/final-form/react-final-form/issues/130
 */
export default props => <Field parse={identity} {...props}/>;
11reactions
petermikitshcommented, Sep 27, 2018

The fact that parse, by default, isn’t an identity function (e.g., value => (value)) is not what I would expect. @erikras, thoughts?

I can speak to my use case (maybe it applies to others-- I am migrating from redux-form, but I don’t want to sound like a special snowflake, either). I have an existing record I am editing via HTTP PATCH. The field in question cannot be null – this is enforced at the database level. If a user clears the field, it will be null, and thus its key will be set to undefined in the onSubmit function. (Analogously, I believe it would have been an empty string in redux-form).

By the time the object makes it to my ORM and ultimately becomes a SQL statement, the deleted property isn’t included in the UPDATE sql statement. So the HTTP PATCH request successfully executes. The user then assumes the request is valid, but if they refresh the page, they would see the value they attempted to delete is still there. The fact that the user had entered an empty string in the text input was valuable – I used that to throw an error.

Again, this might be my personal super snowflake use case, but I’m curious if it’s something others have encountered. Maybe this is more of an issue with my ORM neglecting to attempt passing the undefined value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

state is cleared, but input field text is not after form is submitted ...
I've managed to clear the state once the form is submitted with 'this.setState({newTodo: ''})' (indicated by hitting submit again will add an ...
Read more >
Troubleshooting for RDS Proxy - AWS Documentation
A State value of UNAVAILABLE indicates a temporary or permanent connection problem. In this case, examine the Reason and Description fields.
Read more >
APPENDIX D: VALUATION PROTOCOL - HUD
APPENDIX D: VALUATION PROTOCOL. The appraisal process is the lender's tool for determining if a property meets the minimum requirements.
Read more >
filebeat.reference.yml - Elastic
If left empty, # Filebeat will choose the paths depending on your OS. ... #clean_inactive: 0 # Removes the state for file which...
Read more >
Excel spill range explained - Ablebits
Spill range refers to an array of values returned by a dynamic array ... To remove all values in the spilt area, delete...
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