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

Form controls values are not updated #155

Closed
abdulhaq-e opened this issue Oct 24, 2016 · 7 comments
Closed

Form controls values are not updated #155

abdulhaq-e opened this issue Oct 24, 2016 · 7 comments

Comments

@abdulhaq-e
Copy link

Hello

I have a problem updating form control values. Using valueUpdates, I'm able to update the value property of the DynamicFormModel. This update however, is not reflected on the form control.

The piece of code responsible for this update is L52-L57. What is happening in my case is that the subject is not pushing any values to the stream. For example, if I change those lines to:

if (this.model instanceof DynamicFormValueControlModel) {
    let model = <DynamicFormValueControlModel<any>> this.model;
    console.log("Do you see me?");
    model.valueUpdates.subscribe(val => console.log("Do you see me now?"))
    this.subscriptions.push(model.valueUpdates.subscribe(val => {
        console.log("What about now?")
        this.onModelValueUpdates(val)
    }));
}

The results: I can only see the first sentence in the log. The others do not appear because the subject has not emitted anything.

@udos86
Copy link
Owner

udos86 commented Oct 25, 2016

@abdulhaq-e I had a quick look before work and in the sample app it's working. You need to update the value via next function of Rx.Subject:

this.exampleModel.valueUpdates.next("My new value");

@abdulhaq-e
Copy link
Author

I replicated the code in the sample app and it worked. However, the original issue still exists and I now know what it is.

This line this.exampleModel.valueUpdates.next("My new value"); will have no effect if it's placed inside ngOnit. I've yet to figure out why.

@abdulhaq-e
Copy link
Author

Okay, learned something now. The reason the value is not emitted is because the DynamicFormControlComponent has not finished initialising. By setting a time-out in ngOnit the form control value will change:

setTimeOut( () => this.exampleModel.valueUpdates.next("My new value"), 2000);

Now I'll have to figure how to do this programmatically. Probably using lifecycle hooks.

@abdulhaq-e
Copy link
Author

import {AfterViewInit} from '@angular/core'

    // component defined here
    ngAfterViewInit() {
      this.exampleModel.valueUpdates.next("My new value")  
}

I always postponed reading about Angular 2 lifecycle hooks. I learned them the hard way.

Thanks.

@udos86
Copy link
Owner

udos86 commented Oct 26, 2016

@abdulhaq-e Alright, no problem! Thanks for the clarification.

@udos86 udos86 added the core label Jan 29, 2017
@jmaheshTrimble
Copy link

Can i update id or any other properties of the control?

@udos86
Copy link
Owner

udos86 commented Nov 25, 2017

@jmaheshTrimble

With the exception of id you can update any property you want.

But be careful when updating values and disabled state (see README).

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

No branches or pull requests

3 participants