you could put a timer to wait one second or less. then execute the actions you want on the dynamic event.
or try to put the onclick before the dmx-on:click in the code view.(i haven’t tested that)
Why not bind the dynamic event to the change event of the hidden field that gets updated. You have to trigger it using jQuery after updating it, since it doesn’t trigger when the field is updated using javascript.
So in your first static event do onclick="$('#hiddenField').val('newValue').trigger('change')" and on the hidden field have the dynamic event dmx-on:change="(value == 'something').then(browser.goto('newPage'))"
Ok so I got the order to work by doing a timeout. However the dynamic event is only displaying the initial value not the updated one via the function. Any Advice:
Hi.
I just found myself in a situation where I need to update the value of a variable from JS.
But, after reading this and few other posts, I understand that variables should not be changed using dmx.app.data…, instead, use this hidden field method.
But, the dmx-on:change/blur event of hidden field is unable to read its value.
I have tried reading as formid.hiddenfield.value and hiddenfield.value and just value, but everything just returns either empty or undefined.
Also, I found that trigger triggers the change/blur event before the value actually appears on the hidden input. So I used a setTimeout to call trigger, and now value is being set correctly, before dmx event fires, but dmx is still unable to read the value of the field.