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

Update Options in a select asynchronously when using FormGenerator #22

Closed
jfbloom22 opened this issue Aug 17, 2018 · 3 comments
Closed
Assignees
Labels

Comments

@jfbloom22
Copy link

I put together this: https://codesandbox.io/s/kmoj4j2823
But as you see on line 92 in index.js, I don't know how to pass the updated array of options to the select.

My goal is to either update the select with the new options, or wait to add the select until the options have been received.

Perhaps something like this will work:
this.myForm.parent. setControl('nationality', [my updated control]) but I am not sure how to go about building the control for the second parameter. As well as I am not sure the setControl function is available when I am using the FormGenerator.

another idea that might work well:
use something like this.myForm.get('nationality').setMeta({options: newOptionsArray})

@bietkul bietkul self-assigned this Aug 17, 2018
@bietkul bietkul added the bug label Aug 17, 2018
@bietkul
Copy link
Owner

bietkul commented Aug 17, 2018

Thanks for reporting this issue, I'll try to fix it asap.

@bietkul
Copy link
Owner

bietkul commented Aug 19, 2018

Fixed in the latest release, now you can update fieldConfig whenever you want but beware to frequently & unnecessary updates, because whenever the fieldConfig changes the whole form will be mounted again.
For your use case I'll recommend to try one of it instead of using a new config.

@jfbloom22
Copy link
Author

@bietkul thanks for the sandbox!

const nationalityControl = this.myForm.get("nationality");
nationalityControl.meta.options = newOptionsArray;
nationalityControl.stateChanges.next();

Is working perfectly for me. I also took some time to extend the AbstractControl typescript interface:

interface IstateChanges extends Observable<any>{
  next: ()=> void
}

interface AbstractControlEdited extends AbstractControl{
  stateChanges: IstateChanges,
}

If that looks good and you would like me to create a pull request, just let me know.
Also do you accept any crypto currencies?

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

No branches or pull requests

2 participants