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

Intended Behavior for WATCH function in component? #49

Closed
DPain opened this issue Oct 18, 2019 · 2 comments
Closed

Intended Behavior for WATCH function in component? #49

DPain opened this issue Oct 18, 2019 · 2 comments

Comments

@DPain
Copy link
Contributor

DPain commented Oct 18, 2019

Hi, I was able to implement a load preset feature using j-Input and the WATCH function provided by jComponent inside a Flow component.

When choosing a value on the j-Input, it would pre-fill other text boxes based on the preset chosen.

The intended functionality works fine, but whenever I open the Flow component that contains the j-Input, the WATCH function automatically triggers even if I set the init parameter as false. I assume the initial filling out information by Flow is causing the WATCH function to trigger. I tried using the $setter configuration as well and it behaves identically as the WATCH function.

As a result, this behavior causes the WATCH function to override whatever was already on the text boxes back to the default preset values.

Is this an intended behavior where the the WATCH function will trigger when opening a component? If so, could you recommend me another approach I can take?

Thanks as always :)

@molda
Copy link
Contributor

molda commented Oct 18, 2019

If the path you are watching is let's say settings.component_name.input then the watcher will fire when you open the settings form because settings.component_name is set again.
What you can do is to check if the path is really settings.component_name.input like this:

// this watcher will fire when settings form opens because `settings.component_name` changed
WATCH('settings.component_name.input', function(path, value, type){
    if (path === 'settings.component_name.input')
        console.log('i have changed');
});

@DPain
Copy link
Contributor Author

DPain commented Oct 21, 2019

If the path you are watching is let's say settings.component_name.input then the watcher will fire when you open the settings form because settings.component_name is set again.
What you can do is to check if the path is really settings.component_name.input like this:

// this watcher will fire when settings form opens because `settings.component_name` changed
WATCH('settings.component_name.input', function(path, value, type){
    if (path === 'settings.component_name.input')
        console.log('i have changed');
});

Thanks! That's exactly what I was looking for. I didn't know the patch value could've been utilized that way :)

@DPain DPain closed this as completed Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants