Modify a local variable using javascript issue


Hi,


I just started to create a "drag and drop" plugin. I already did it in traditional web and now I try to do it in reactive web app.


However, I have a problem with assigning a local variable using a javascript script. When the "drop" function is activated (see screenshot), the click is made and the value of the input is modified. However, the value of the local variable doesn't change (it is indeed linked to the input).


I have already used this technique in traditional web and from what I saw it should work in reactive web app.


If anyone has an idea, I'm interested.

Thank you !


Maxime

Hi Maxime,

You have to do a slight changes in the defined JS code...

Instead of using the below JS statement (referred from your code)

Code Snippet

document.getElementById("" + $parameters.ElementId + "").value = "Dropped";


Use the below JS code to set the input widget value property.

Code Snippet

document.getElementById($parameters.ElementId).value = "Dropped";


Note: Don't place "" (double quotes) within the document.getElementById() before and after the element ID ("$parameters.ElementId")


I tested the code and it's working as expected :)


Hope this helps you...


Regards,

Benjith Sam

Hi Benjith,


Thank you for your answer.


I made the modification that you recommended to me. 

Unfortunately, that doesn't change my problem. 


Maybe you can send me an oml file of what you tried so that I can see and compare.


Thanks again,


Maxime


Hi Maxime,

- In traditional web, if we have to modify the local variable using JS, usually we use to map the local variable with a hidden input widget and using js .click() we would trigger a hidden button which in-turns execute the Hidden Button action flow and update the local variable as well as continues with the other business stuff..

- In reactive web and mobile, we can directly call the Screen action in JS node to update the Local Variable value without requiring to click a hidden button or to introduce an hidden input widget to achieve the requirement.

Previously mentioned "" quotes note is not the cause.

Just try to trace the browser console section to know any kind of occurred run-time error.


Hope this helps you!


Regards,

Benjith Sam

Thanks again Benjith,


I did not know that it was possible to trigger an action this way. 

However, I have to pass a dynamic value in place of "dropped" (elementId show in the screenshot)


Is it possible to pass input parameters with this method?

If not, I think I have to use an input element.


Regards,

Maxime


Solution

Hi Maxime,

Yes, it is possible to pass the screen action input parameter value, in the action call statement as mentioned below.

Code Snippet

$actions.ModifyLocalVarValue('Dropped');

Hope this helps you!

You are welcome :)


Regards,

Benjith Sam

Solution

Thank you very much ! It works perfectly!


I struggled because I was using the "ElementId" attribute to pass the data between the draggable element and the drop area.


Apparently this attribute doesn't work. So I used the "data-id" attribute.


Thanks again to you Benjith,


Regards,


Maxime

You are welcome Maxime :)

Thank you very much for sharing the final implementation and knowledge :)


Glad I could be of help!


Regards,

Benjith Sam