Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi step form with same model object #1358

Closed
GetTaxSolutions opened this issue Jan 2, 2019 · 13 comments · Fixed by #1820
Closed

Multi step form with same model object #1358

GetTaxSolutions opened this issue Jan 2, 2019 · 13 comments · Fixed by #1820

Comments

@GetTaxSolutions
Copy link

I'm using your example and have two fields which point to same key in model but they are in two different steps in wizard. When I fill first one It have to update input field in second step as well but it's not. When try to write something in second step it update exact same property in model.
Example /field 'First name *' in first and second steps in the wizard/ :

https://stackblitz.com/edit/angular-p5rqay?file=src/app/app.component.html

@aitboudad
Copy link
Member

unfortunately that's an angular issue angular/angular#13792, not sure how it can be solved.
for now you can use the following workaround https://stackblitz.com/edit/angular-p5rqay-mvw7vu

@GetTaxSolutions
Copy link
Author

Thank you for your info. I tried workaround, it populated two properties in model but in second step the field is empty again. May be have to wait to be fixed in angular.

@aitboudad
Copy link
Member

the angular fix may take a long time, you may remove the extra property before submitting your form instead.

@flobiber
Copy link

flobiber commented Oct 2, 2019

@aitboudad if i have a look on your workarround, i don't see that this is working. If i go to the second step of your wizard, the name field is empty

@aitboudad
Copy link
Member

@flobiber updated the example, using *ngIf solve the issue without using my workaround
https://stackblitz.com/edit/angular-p5rqay-mvw7vu

@flobiber
Copy link

flobiber commented Oct 3, 2019

@aitboudad Okay i think i miss understand the original problem. My problem is more like this:
https://stackblitz.com/edit/angular-p5rqay-mlucvv?file=src/app/app.component.ts

@aitboudad
Copy link
Member

you may use the following workaround https://stackblitz.com/edit/angular-p5rqay-hkrc18 for now until angular team fix that issue

@aitboudad
Copy link
Member

aitboudad commented Oct 3, 2019

@aitboudad
Copy link
Member

@flobiber I've pushed a fix in v5.5.0 so the workaround is not necessary anymore 😄!

https://stackblitz.com/edit/angular-p5rqay-hkrc18

@paritosh291219
Copy link

Can i use customise model in multi step formly field.
For eg when I clicked submit button i want to fill my own model. I want to fill value in defaultValue in formlyfieldconfig

@instantgis
Copy link

My forms work in distinct Edit and Search modes. it defaults to search mode.
In Search mode I use a date range picker for a date field.
In Edit mode I want to use a date picker instead for the same field.
I want to use the same key names.

The idea is I'd hide/show the different controls based on edit mode.

I tried this..

https://stackblitz.com/edit/ngx-formly-duplicate-keys?file=src%2Fapp%2Fapp.component.ts

And it appears to work. However there is something that does not make sense...

toggle() {
this.editMode = !this.editMode;
console.log(this.editMode);
this.fields[0].hideExpression = this.editMode;
this.fields[1].hideExpression = !this.editMode;
// ??
// this.fields.forEach(f => (f.hideExpression = this.editMode));
}

Why did I have to invert the hideExpressions for the different fields?

Why does this not work?
this.fields.forEach(f => (f.hideExpression = this.editMode));

What am I doing wrong?

@aitboudad
Copy link
Member

@instantgis it's just an example, you can also make it globally by using formState with the combination of custom extension

@yoganantham-web
Copy link

yoganantham-web commented Aug 25, 2022

@GetTaxSolutions @aitboudad
I fixed this issue.
Please use like below.

fields: FormlyFieldConfig[] = [{
    type: 'tabs',
    fieldGroup: [
      {
        **key: "Personal data",**                      ### _Insert key here (tab label)_
        templateOptions: { label: 'Personal data' },
        fieldGroup: [
          {
            key: 'firstname',
            type: 'input',
            templateOptions: {
              label: 'First name',
              required: true,
            },
          },
          {
            key: 'age',
            type: 'input',
            templateOptions: {
              type: 'number',
              label: 'Age',
              required: true,
            },
          },
        ],
      },
      {
        **key: 'Destination',**           ### _Insert key here (tab label)_
        templateOptions: { label: 'Destination' },
        fieldGroup: [
         {
            **key: 'firstname',**                     ### _Duplicate field_
            type: 'input',
            templateOptions: {
              label: 'First name',
              required: true,
            },
          },
          {
            key: 'country',
            type: 'input',
            templateOptions: {
              label: 'Country',
              required: true,
            },
          },
        ],
      },
      {
        templateOptions: { label: 'Day of the trip' },
        fieldGroup: [
          {
            key: 'day',
            type: 'input',
            templateOptions: {
              type: 'date',
              label: 'Day of the trip',
              required: true,
            },
          },
        ],
      },
    ],
  }];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

6 participants