Custom default code is not fired when the control is redrawn i.e. if we set one control to redraw on change of another control , then its custom default value should be fired every time it is redrawn but this is not happening [BUG]
Environment
Please provide as many details as you can:
- Hosting type
- [ ] Local deployment
- Version: 4.2.6
- [ ] Local deployment
- Formio.js version:4.2.6
- Frontend framework: angular-formio
- Browser: Google Chrome
- Browser version: 77.0.3865.90 (Official Build) (64-bit)
Steps to Reproduce
- Take a select component on form as "Country" and bind some values hardcoded from data tab.
- Take another Text Field component on form. Set Redraw On as Country. Add some code in "Custom Default Value" section.
- Save the form.
- Run the from and change value from country component.
Expected behavior: Code written in "Custom Default Value" section should be run on every selection change of Country component.
Observed behavior: Code written in "Custom Default Value" section is not being run on every selection change of Country component.
Example
NA
The Custom Default value does not re-evaluate when the component is "redrawn" and this is by design. You may be asking for "Calculated Value" with the "Allow Override" checked. That probably will give you what you want out of this.
We want to call a API with value of the select component as a query string parameter. If we do that in calculated Value the API will keep on calling multiple times. Is there a way to call the API only when component is redrawn.
The custom default value is only called when setting the default value (i.e. at component initialization). If you want to run custom code when a component is redrawn, you will probably need to listen to the "render" event on the form that fires every time a component is rendered. There is also an "attach" event when the rendered dom element has its events attached and might be more in line with what you are looking for.
Hello , i am also looking for this kind of functionality but not able to perform, I tried with "render" event but not able to listen the event , while i am changing the value from dropdown render method is not calling , please provide any suggestion how we can achieve this Thanks
Rendering or redrawing does not indicate that the data should be defaulted again. One thing you could do is add a listener to the instance within the default value and do whatever it is you want to do.
For example:
instance.on('change', function(event) {
// do something based on a change.
})
}
You can add this within the custom default value since it will only run once when the component is initialized.