I have a set of hidden inputs, which are updated using a custom JS implementation.
On click of a button, I call a server connect load function, and bind all the hidden inputs as various GET parameters.
This setup was working fine with AC1, but with AC2, these hidden fields bindings return empty.
Have tried dispatch the update event from JS, but it does not have any effect.
The JS function GetFullPhoneNumber updates hidden fields like txtDefaultContactContryCode etc.
Then on button click, when trying to send that value in SC, the binding returns null.
From the foroum topics, I have noticed that a few components/elements in AC2 have difficulty on default values or initialization...
Can you test it by giving a static value on your hidden inputs and check the result?
I can't test it (still on AC1...)
(If that rings a bell, maybe working on this way you can fix it... )
Yes, I can see the updated value in Elements tab, and also if I try to get the data using JS.
Only Wappler bindings are unable to read this - dmx.app.data and dmx.parse don't work either.
When you update an input from JavaScript the component doesn't know about it, setting the value programmatically doesn't trigger any event.
// get the dom element
const input = document.getElementById('txtDefaultContactCountry');
// update the value
input.value = 'Netherlands';
// trigger a change event to let the App Connect know it was updated
input.dispatchEvent(new Event('change'));
I tried jQuery trigger function, and that did not work. $("#txtDefaultContactContryCode").trigger('change')
Will try again with vanilla JS.
The dev working on this also added this and it worked. I don't know what it does, so will probably not keep it. document.getElementById('txtDefaultContactCountry').dmxComponent._changeHandler();
jQuery doesn't trigger a native DOM event but has its own events which only work with jQuery.
That calls the internal method that also is being called after a change event is triggered. So it does the same but the method could change in the future since it is not a public api.
This triggers the updated event on the component but doesn't update any internal state.