Comments (9)
Hi. The form data flow is straight forward
model -> form(data inputs) -> resulting model(output)
You can change the data in model, but form itself does not care about model anymore after initialisation. so you have to change the data in form to see the results on screen. Or you can change the model and then trigger rebuild.
The listed code and description signifies that your goals could be achieved in easier way.
this is very strange part
initState: (context, formModel) {
vm.initState(context, formModel: formModel);
},
this type casting smells
model: (vm as DetailsFormVm).formModel?.model ?? vm.initialValue,
from reactive_forms_generator.
@vasilich6107 Thanks. My main issue is that I am passing in this model:
But then in the build method the formModel does not equal the model:
This seems wrong.
I deliberately removed initState so that it could not tamper with the formModel.
I will keep investigating.
from reactive_forms_generator.
I think i need to re-trigger initState
in DetailsFormBuilder
. However It doesn't trigger by calling setState in my parent widget.
from reactive_forms_generator.
You can change the data in model, but form itself does not care about model anymore after initialisation. so you have to change the data in form to see the results on screen. Or you can change the model and then trigger rebuild.
All sorted thank you, I needed to call formModel.updateValue
as you mentioned to update the form with the new value. I have put it in the builder for simplicity but will refactor.
builder: (context, formModel, child) {
formModel.updateValue(vm.formModel?.model ??
Details(companyName: 'default', name: 'default', description: 'default'));
return Column(children: [
from reactive_forms_generator.
Not sure that putting update value in builder is a good idea. Cause build method should not contain side effects
if you could provide minimal repo with your use case I will try to help you
from reactive_forms_generator.
@vasilich6107 Great, thanks! I'll let you know when I get time to refactor.
from reactive_forms_generator.
@vasilich6107 The formModel inside the builder method is not persistent, so to make it equal to my vm.formModel?.model
, It must either be set inside the builder method, or the ReactiveFormBuilder must be re-initialised (initState needs to run again), however I do not know how to re-initialise it, lots of things make it rebuild but they do not make it re-initialse.
from reactive_forms_generator.
You can change the data in model, but form itself does not care about model anymore after initialisation. so you have to change the data in form to see the results on screen
@vasilich6107 Does this mean that if we need to update the form, we need to persist the form as a class property, so that we have a reference to the form to update it? I have been refactoring to get rid of state and I deleted the FormModel
from my components, which is fine in normal scenarios, but in this instance, using an abstract factory pattern, I do need to change the data in the form as you have mentioned above, so I guess i will need to persist the FormModel
? Without persisting the FormModel
, I tried just calling formModel.updateValue()
inside the ReactiveFormBuilder
builder
and it caused an infinite loop of rebuilds.
from reactive_forms_generator.
No matter what I do, the formModel
param passed to the builder here:
builder: (context, formModel, child) { return Column(children: [
is completely empty. It is a model where every property is null
.
I pass the model to the FormBuilder fully populated with values and the builder method just spits out an empty model no matter what I do so the text fields don't show the right value :(
child: DetailsFormBuilder(
model: x.model as Details,
initState: (context, formModel1) {
vm.initState(context, formModel: formModel1 as DetailsForm);
},
builder: (context, formModel, child) {
return Column(children: [
from reactive_forms_generator.
Related Issues (20)
- didUpdateWidget sets the form to pristine and untouched HOT 5
- How to use non-const validators HOT 3
- Freezed: Generated *.gform.dart contains errors (Generated duplicated code) HOT 4
- Calling the generated FormModel's `remove<Model>ItemAtIndex()` appears buggy. HOT 9
- 0.23.2 causing an infinite loop HOT 9
- New FormModel.reset method behaves slightly different to FormGroup equivalent HOT 6
- Cant add validators to freezed classes. HOT 4
- Provider / Riverpod plugin HOT 10
- How to populate the form from some business logic/repository pattern? HOT 3
- [bug] @FormGroupAnnotation validators aren't respected HOT 1
- Shared models are generated twice HOT 4
- support for generics? HOT 6
- generated FormBuilder should call `initState` on `didUpdateWidget` HOT 3
- Generated classes missing the resetValue member HOT 12
- Example of a ReactiveFormsGenerator on ViewModel HOT 4
- The casing of key names of Form value is different from what Freezed package generated HOT 7
- The static formControlNames could be const HOT 2
- Validators set programmatically get cleared on didUpdateWidget HOT 1
- Programmatically Add controls HOT 2
- @FormArrayAnnotation() with inheritance HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive_forms_generator.