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

FormArray fields value updating #378

Closed
mga47 opened this issue May 31, 2017 · 5 comments
Closed

FormArray fields value updating #378

mga47 opened this issue May 31, 2017 · 5 comments
Labels

Comments

@mga47
Copy link

mga47 commented May 31, 2017

Hi
I have some problems when try to use FormArray functionality.

issue

In each row I have 2 select boxes, and the options of second select box depends on first select box value.
I found the solution of this problem. After onChange() action in first select box I remove the appropriate row from arrayModel, change the createGroup method implementation and insert the row in old place. Now the problems.

  1. I don't know which row select box value changed. I can't pass the row number to my method.
  2. Because of problem 1 I decide remove all rows where select box Id and Value equal to $event.model ID and Value. after that I try to return old values to my fields like this, and nothing happened.
    (this.arrayModel.groups[rowNum].group[itemVal] as DynamicFormValueControlModel<string>).valueUpdates.next(array[+itemVal]);

When I try after this line of code recreate FormGroup and ArrayControl, like this:
this.formGroupGrid = this.formService.createFormGroup(this.formModelGrid); this.arrayControl = <FormArray> this.formGroupGrid.get(RlappConstants.gridName);
I get an error

I can give you plunker example upon your request.

P.S
Thanks for great library )

@udos86
Copy link
Owner

udos86 commented Jun 2, 2017

@garnikmkrtchyan Thanks for your message!

After reading through your issue my conclusion is that adding additional information to the change event for FormArray controls would solve your problem, right?

@udos86 udos86 added the core label Jun 2, 2017
@mga47
Copy link
Author

mga47 commented Jun 3, 2017

It will solve my problem partially. Even if I know which row I must replace, the valueUpdateing functionality doesn't work in this case.

@udos86
Copy link
Owner

udos86 commented Jun 3, 2017

I think it would solve your problem as long as you avoid recreating the FormGroup again because I assume this leads to a mess of lost references.

You've already figured out correctly how to update the value of a FormArray control:
this.arrayModel.get(1).get(0).valueUpdates.next("new value");

So if we extend the change event by adding a context information from which you can read the row index you could directly call valueUpdates.

udos86 added a commit that referenced this issue Jun 3, 2017
@mga47
Copy link
Author

mga47 commented Jun 5, 2017

Thanks for your answer @udos86 .
I can give you some additional info about this issue, that may help you later.

After creating a FormArray (that contain only one row), I call Initialize method to fill it from my dataset. All this work fine, row after row it create and fill my grid.

But if I try later update some rows values by same mechanism, I get errors. From that errors I understand, that inner structure of FormArray was broken, and some references contain wrong (maybe old) values.

That's all about this. Now my problem solved by another way, and I hope that you can provide a more simple mechanism to valueUpdating.

@udos86
Copy link
Owner

udos86 commented Jun 5, 2017

@garnikmkrtchyan Ok!

Nevertheless 1.4.12 will deliver some enhancement for DynamicFormControlEvent.

@udos86 udos86 closed this as completed Jun 5, 2017
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