Text box driven by array variable / dropdown

Questions and discussion about using ProcessMaker 2: user interface, running cases and functionality

Moderator: amosbatto

Forum rules
Please search to see if a question has already been asked before posting. Please don't ask the same question in multiple forums.
JarodC
Posts: 9
Joined: Wed May 04, 2016 12:22 am
Country: Australia

Text box driven by array variable / dropdown

Unread postby JarodC » Tue Aug 02, 2016 10:32 pm

Hi, I have a standard scenario where I'm using a dropdown to select a record filled from an underlying array, but I can't see how you fill the associated text boxes on change.

The datasource is an external app accessed via service call rather than sql so can't use that.

I can't see how the 'array variable' datasource works for dependent record fields/text boxes, or can this be done through javascript?

Any help appreciated?

mishika
Posts: 156
Joined: Thu Feb 16, 2017 3:03 am
Country: India

Re: Text box driven by array variable / dropdown

Unread postby mishika » Tue Apr 18, 2017 3:15 am

Hello,

To achieve your requirement, please do the following:

1. Create a trigger which assigns value to an array variable which in turn is json encoded and assigned to an hidden field in the Dynaform. The trigger can be something like this:

Code: Select all

$arr =  array(
           array('1', 'a'),
           array('2', 'b'),
           array('3','c'),
           array('4','d')
         );
@@hdn = json_encode($arr);


2. Assign this trigger before Dynaform.
3. In the dynaform take a hidden field with ID @@hdn.
4. In the Dynaform write the following javascripts:

1. populatearray:

Code: Select all

var aProducts = eval(getValueById("hdn"));
if (typeof(aProducts) == 'object' && aProducts.length) {     //if an array
   for (var i=0; i < aProducts.length; i++) {
      var opt = document.createElement("OPTION");
      opt.value = aProducts[i][0];
      opt.text = aProducts[i][1];
      getField("dd1").options.add(opt);
   }
}

2. changetextval:

Code: Select all

var changeDrop = function () {
    var idx = getField("dd1").selectedIndex;// name of the dropdown
    var selectedValue = getField("dd1").options[idx].value;
    getField("text1").value = selectedValue;
 };
 var dynaformOnload = function() { // calling the function
    leimnud.event.add(getField('dd1'), 'change', changeDrop );
    changeDrop();
 };

where dd1 is the ID of dropdown and text1 is the ID of text box which is the dependent field on dropdown.
This sets the value of the textbox as the value of the option selected in the dropdown.

Hope this helps.

Best Regards
Mishika
Mishika


Return to “Using ProcessMaker 2”

Who is online

Users browsing this forum: No registered users and 2 guests