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 hvillemoes
#822783
I have a form, where a checkbox controls the display of a subform.
Below code in the form works at entry (hides the subform) and when I click the checkbox (displays the subform).
But when I then again removes the check, the subforms no longer disappears.
All hints are appreciated.
Code: Select all
function ShowHideOracle(newVal,oldVal)
{
  if ( newVal == '0' ) {
    $('#OraDatabaseInstances').disableValidation();
    $('#OraProcesses').disableValidation();
    $('#OraDbFiles').disableValidation();
    $('#OraRedoLogs').disableValidation();
    $("#8979782105c5302564bd1d9006827115").hide();
  } else {
    $("#8979782105c5302564bd1d9006827115").show();
    $('#OraDatabaseInstances').enableValidation();
    $('#OraProcesses').enableValidation();
    $('#OraDbFiles').enableValidation();
    $('#OraRedoLogs').enableValidation();
  }
}

$('#OracleWanted').setOnchange(ShowHideOracle);

$('#OraDatabaseInstances').disableValidation();
$('#OraProcesses').disableValidation();
$('#OraDbFiles').disableValidation();
$('#OraRedoLogs').disableValidation();
$("#8979782105c5302564bd1d9006827115").hide();
User avatar
By amosbatto
#822790
You aren't checking correctly for the value of the checkbox. In version 3.2 and later, setOnchange() will report its value as '"0"' or '"1"'. If you are getting the value with getValue(), then it will be "0" or "1".

You need to use code like this:
Code: Select all
$("#showProductInfo").setOnchange(showHideProductInfo); //when checkbox changes value

showHideProductInfo( $("#showProductInfo").getValue(), "");  //when form loads
  
function showHideProductInfo(newVal, oldVal) {
  if (newVal == '"0"' || newVal == "0") {
    $("#9658653295c5a6e34098395019812830").hide();
  }
  else {
    $("#9658653295c5a6e34098395019812830").show();
  }
}
You shouldn't assume the checkbox will be unchecked and the subform is hidden when the form is loaded, because the user may be reloading the form.
By richvle
#826047
What's the proper syntax if I have the subform UID already?

$SubformUID = $("#SubSection_SubprocessUID_ADP").getValue(); //#SubSection_SubprocessUID_ADP is a hidden control, and the value is 9658653295c5a6e34098395019812830
$($SubformUID).hide();
amosbatto wrote: Thu Feb 07, 2019 1:21 am You aren't checking correctly for the value of the checkbox. In version 3.2 and later, setOnchange() will report its value as '"0"' or '"1"'. If you are getting the value with getValue(), then it will be "0" or "1".

You need to use code like this:
Code: Select all
$("#showProductInfo").setOnchange(showHideProductInfo); //when checkbox changes value

showHideProductInfo( $("#showProductInfo").getValue(), "");  //when form loads
  
function showHideProductInfo(newVal, oldVal) {
  if (newVal == '"0"' || newVal == "0") {
    $("#9658653295c5a6e34098395019812830").hide();
  }
  else {
    $("#9658653295c5a6e34098395019812830").show();
  }
}
You shouldn't assume the checkbox will be unchecked and the subform is hidden when the form is loaded, because the user may be reloading the form.
User avatar
By amosbatto
#826052
richvle wrote: Mon Aug 19, 2019 2:59 pm What's the proper syntax if I have the subform UID already?

$SubformUID = $("#SubSection_SubprocessUID_ADP").getValue(); //#SubSection_SubprocessUID_ADP is a hidden control, and the value is 9658653295c5a6e34098395019812830
$($SubformUID).hide();
You forgot to add the "#" and $ is not necessary in JavaScript. $ is used as an alias for jQuery, so you should avoid it for your variables.
Code: Select all
//#SubSection_SubprocessUID_ADP is a hidden control, and the value is 9658653295c5a6e34098395019812830
var SubformUID = $("#SubSection_SubprocessUID_ADP").getValue(); 
$("#" + SubformUID).hide();
Task doesnt have any users.

Amosbatto: One more thing if you can help me with.[…]

Just guide me to implement this?

Hi, I have a text control (rfq_segment) and I wan[…]

Genial!!! gracias. :D i need to translate an[…]