Jquery Function in Dynamic Events


#1

How can I add a function and execute it in dynamic events. Why I am using dynamic as apposed to static?

  1. I can’t seem to get the static to run before the dynamic.
  2. I want to run a script update a hidden field and have the dynamic event to check the value and if the value is good do something else.

So is it possible to call a function in dynamic events?


How can I use returned javascript result to app connect variable
#2

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)


#3

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'))"


#4

Man when I read this I was like yes why didn’t I think of this. However it still runs the dynamic event first. Any more suggestions


#5

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:

function snippet

if(status == “valid”)
{
$$(’#status’).val(status);
var isStored = $$(’#status’).val();
myApp.dialog.alert(isStored);
setTimeout(function ()
{
$$(’#status’).trigger(‘blur’);
}, 8000);


#6

you want the dynamic to execute after the static.
did you try the solution i suggested? using action scheduler.


#7

My apologies. I have now tried it and it works perfectly. Thanks a lot


#8

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.

Please help @patrick / @yarycling / @mrbdrm