Closed introspection3 closed 3 weeks ago
change field.options.items = data; to field.w2field.options.items = data;
This will update and populate list at runtime.
There is no need to refresh form. You will not need to execute - w2ui.tunnelForm.refresh();
Hope this helps!
@WillTheFarmer thanks for that, lifesaver! I had been banging my head trying to update a list on a form on a popup.
BTW I have found that depending on whether the form has been previously rendered that you have to do either of the methods above. That is, if the form has not been rendered then field.w2field is undefined and will error.
`let field = w2ui.form_source.get(FieldName);
if (field.w2field){ //Form has been rendered before field.w2field.options.items = services; } else { //Form has not been rendered before field.options.items = services; }`
@ope-nz you're welcome! Yes, depends if form has been rendered. I banged my head for a while as well and spent many hours going through w2ui class code and using Chrome DevTools. First time through onRender works without w2field. I add form properties to track methods that fire often. Example:
onRender: function (event) {
console.log('onRender', event);
if (this.lonRender) {
console.log('onRender - THIS IS THE ONLY TIME THIS WILL EXECUTE.');
this.lonRender = false;
this.requeryDropdowns();
};
},
You should also be able to do this
w2ui.tunnelForm.set("targetClientId", { options: { items: data }})
which regenerates the field too
@vitmalina sorry to flog a dead horse here but the approach you posted does not work for a form in a popup. I dont know if this is because it is in a popup but the behaviour is different.
This does not work for a form in a popup;
w2ui.tunnelForm.set("targetClientId", { options: { items: data }})
This does work for a form in a popup;
let field = w2ui.form_source.get(FieldName);
if (field.w2field){
//Form has been rendered before
field.w2field.options.items = services;
}
else
{
//Form has not been rendered before
field.options.items = services;
}
Short description dear sir,how to change combo items at runtime."can't refresh"
What is current behavior ...
What is desired behavior ...
Link to jsfidle/codepan with sample code ...
Steps to reproduce or sample ...