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.

How to set fields to its default value inside constructor of form class

See original GitHub issue

I’m trying to call the mobx react form more than once and the problem is that when I call it suppose the second time, the field has the same value as it was updated the first time.

constructor(props) { super({ fields }, { plugins }); this.newFields = Object.assign({}, fields); }

So the newFields has the previous updated value every time I try to call the form. How can I get the default fields value like every time when I call the form?

One thing I found is that when I manually refresh the page, the fields gets back its original value which is obvious. Please correct me if I’m going wrong, I’m new to React and using this for the first time.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
utftufutukgyftryidytftuvcommented, Apr 4, 2019

pls do applying default values by d-e-f-a-u-l-t

0reactions
pdfowlercommented, Sep 4, 2019

@utftufutukgyftryidytftuv FWIW, here’s how I handle applying default values on form init:

export function init(
  values = {},
  defaults = {
    roles: ['user'],
  },
) {
  return new MyForm({
    fields,
    values: _.defaults(values, defaults),
    defaults,
  });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Django set default form values - Stack Overflow
You can use Form.initial , which is explained here. You have two options either populate the value when calling form constructor:
Read more >
Default Constructor in Java – Class Constructor Example
In this article, we will talk about constructors, how to create our own constructors, and what default constructors are in Java.
Read more >
How to provide default values for Scala constructor parameters
Give the parameter a default value in the constructor declaration. Here's a simple declaration of a Socket class with one constructor ...
Read more >
Initialize Property Values - MATLAB & Simulink - MathWorks
Define properties with default values — MATLAB ® assigns the same initial value to the property of every instance. Set property values in...
Read more >
Classes and methods - Finance & Operations | Dynamics 365
In this article. Declare a class; Fields; Constructors; Create an instance of an object; Destructors; Methods; Method modifiers ...
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