Giter VIP home page Giter VIP logo

Comments (9)

vasilich6107 avatar vasilich6107 commented on June 30, 2024

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.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

@vasilich6107 Thanks. My main issue is that I am passing in this model:

Screenshot 2022-11-06 at 11 25 49 AM

But then in the build method the formModel does not equal the model:

Screenshot 2022-11-06 at 11 44 58 AM

This seems wrong.

I deliberately removed initState so that it could not tamper with the formModel.

I will keep investigating.

from reactive_forms_generator.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

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.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

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.

vasilich6107 avatar vasilich6107 commented on June 30, 2024

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.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

@vasilich6107 Great, thanks! I'll let you know when I get time to refactor.

from reactive_forms_generator.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

@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.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

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.

BenjiFarquhar avatar BenjiFarquhar commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.