pass value from variable to UI macro

Pastupe
Mega Guru

Hello, I dont know how to set variable value to UI macro.

I have UI macro below and onchange client script

Onchange client script is able to alert me with variable, but I doesnt need alert, need to set this value to UI macro on form. So when user select value in field A, html data should be populated to field B ( field B is UI macro )

How can I do it ? Should I better create some UI page and pass data through ?

Actually I will need to pass html value to UI macro field through onchange wizard script.

thank you

/Petr

UI macro

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<html>

<head>

<script>

function checkDetails()

{

  var selected_training = g_form.getReference('u_select_training');

  var u_selected_training_description = selected_training.short_description;

alert('from date :'+u_selected_training_description);

}

</script>

</head>

</html>

</j:jelly>

Wizard Client Script

function onChange(control, oldValue, newValue, isLoading) {

if (!isLoading){

checkDetails();

}

}

1 ACCEPTED SOLUTION

adiddigi
Tera Guru

If I understand it right, it's fairly easy.



This is what I understood so far:



- You want to set a HTML field on the UI Macro with the Short_Description of the select training field on the form.


- One thing that's missing is the HTML of the field in the UI Macro.



Here is very small snippet I have set up:



My UI Macro has a field called "short description" which is an input, which I will be setting on Change of a field on the form. Here is the UI Macro. Notice the Script that's inside the UI Macro:




<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


Short Description: <input id="short_description" type="text"/>





  <script>


  function setDesc(text){


  $j("#short_description").val(text);


  }



  </script>


</j:jelly>





Now, the easy part : write an onChange script to call the setDesc. Because `setDesc` is loaded on the global name space you should be able to call it like this:




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


  setDesc(newValue);





    //Type appropriate comment here, and begin script below


   


}




Does that help?


View solution in original post

19 REPLIES 19

In this case, then what does the UI macro code look like?


Below should be the code in UI Macro



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<div id="short_description"/>


  <script>


  function setDesc(text){


  document.getElementById('short_description').innerHTML = text;


  }


    </script>


</j:jelly>





Now in onChange client script use the same code as provided in previous reply.


Thank you Gurpreet!   Much closer but not quite yet.   I will look at this more tomorrow and let you know if it worked or not.   Thanks!


Got it!   Thank you so much   🙂



I had to tweak it a little.   I added this to my client script after my ajax call returns the url as the answer.



  var url = answer;


  var text   = 'Click <a href="'+url+'" target="_blank">here</a> to view an image of the supporting document';


  setDesc(text);



And then my ui macro code is exactly what you gave me.



Thanks!


Rhonda


Thanks! I needed to get the value from a variable on the form so I could do some scripting and couldn't figure out how to get it. This gave me exactly what I needed.