Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By nadobii
#826035
Hi,
I write a javascript code in order to make dependent fields in dynaform. but there is a mistake. at the first time, when the user select "No" the "Reasons for disagreement" appears and it's ok.
but when the user select "Yes" and after that (before submit) select "No" the "Reasons for disagreement" and "description" appear!! while the "description" is related to "Yes" selection. json file is attached.
(6.03 KiB) Downloaded 12 times
this is javascript code:
Code: Select all
$("#action_not_approve_description").hide(); //Hide when the form loads
$("#action_teams").hide();
$("#action_plan_draft").hide();
$("#action_approve_description").hide();

$("#action_approve").setOnchange( function(newVal, oldVal) {
   $("#action_not_approve_description").hide();
  $("#action_teams").hide();
  $("action_approve_description").hide();
  $("#action_plan_draft").hide();
        
    
  if (newVal == "1") { 
    $("#action_teams").show();
    $("#action_approve_description").show();
    $("#action_plan_draft").show();
  }

  if (newVal == "0") { 
     $("#action_not_approve_description").show();
         
  }

});
thanks.
User avatar
By Bosatzu
#826050
Hello!

I don't understand what you want to do......but maybe this code help you (i hope).
Code: Select all
load();

function load(){
    
   	$("#action_not_approve_description").hide();
	$("#action_teams").hide();
	$("#action_plan_draft").hide();
	$("#action_approve_description").hide();
	$("#action_approve").setOnchange(hide_show);
}

function hide_show(){

  	if ($("#action_approve").getValue() == "1") {
      	
  	    $("#action_not_approve_description").hide();
      	    $("#action_teams").show();
	    $("#action_approve_description").show();
	    $("#action_plan_draft").show();
    }
    else{
      	
    	    $("#action_teams").hide();
	    $("#action_approve_description").hide();
	    $("#action_plan_draft").hide();
      	    $("#action_not_approve_description").show();
    }
}
By nadobii
#826059
Thanks a lot :)
the first reply is ok.

my problem was as bellow:
the "description" should be appear when the "yes" is selected, but it appears next to the "Reasons for disagreement" when the "No" is selected.
7.png
7.png (66.71 KiB) Viewed 326 times
User avatar
By amosbatto
#826069
You shouldn't be using a boolean variable for the radio button. You should use a string variable, because you have 3 states: not set, Yes and No. Also, you need to consider that the user might redisplay the form after having already filled out the form.

You should make your form something like this:
(3.69 KiB) Downloaded 15 times
The code is:
Code: Select all
function showOrHideFromAction(decision, oldVal) {    
  if (decision == "yes") { 
    $("#description").show();
    $("#action_not_approve_description").hide();
  }
  else if (decision == "no") {
    $("#description").hide();
    $("#action_not_approve_description").show();
  }
  else { //if decision == ""
    $("#description").hide();
    $("#action_not_approve_description").hide();
  }
}

//when radio button changes:
$("#action_approved").setOnchange( showOrHideFromAction );

//execute when form loads:
showOrHideFromAction($("#action_approved").getValue(), '');
ProcessMaker external Editor

Hi all, I am trying to follow how to use Processm[…]

Hi dan123dan, Even though your answer isn't direc[…]

If your plugin uses this (e.g. to insert data into[…]

Processmaker Installation on Linux

We are trying to install processmaker on linux ser[…]