Page 1 of 1

Change the defaultvalue property

Posted: Mon Jun 10, 2019 5:12 am
by kram327
I'm looking for a way to change the default value of a drop-down field (Purpose) based on another dropdown field (Facility). The idea is to auto populate the commonly selected value for specific facility type, and can change later on if ever the actual value is different from the default value.

I tried using the setValue function but it will not allow to change value anymore.
Code: Select all
	var nRow = $("#GRID_FACILITY").getNumberRows();
	for (; nRow >= 1; nRow--) {
  		if ($("#GRID_FACILITY").getValue(nRow, 2) == 'Term Loan') {
			$("#GRID_FACILITY").setValue("For capital expenditures", nRow, 6);
               }
        }
Found the following in wikipedia, however, i can't follow the instructions:
Code: Select all
	getField("field-name").property-name
	alert(var_dump(getField("field-name")));

Re: Change the defaultvalue property

Posted: Tue Jun 11, 2019 12:25 am
by amosbatto
You have to use form.setOnchange() for this. See:
https://wiki.processmaker.com/3.1/Grid_ ... s_in_grids

Let's assume that the ID of grid is "loadFacilityGrid" and the IDs of your dropdowns are "facility" and "purpose", then your JavaScript code would be something like this:
Code: Select all
var formId = $("form").prop("id");

$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
   var aMatch = fieldId.match(/^\[loanFacilityGrid\]\[(\d+)\]\[facility\]$/);
   //if the "facility" field was changed in the grid, then change the value of the "purpose" field:
   if (aMatch) {
      var rowNo = aMatch[1];
      if (newVal == 'term_load') {
           setValue("capital_expenditures", rowNo, 5);
      }
});
Remember that you are checking for the values (not the displayed labels) in the dropdowns.

Re: Change the defaultvalue property

Posted: Thu Jun 13, 2019 6:57 am
by kram327
Thanks for looking at this, Amos. However, I can't get it to work :(.
Maybe it's not working since I have 2 subforms in the dynaform.

I saw this code in the link that you have provided but didn't work as well:

$("#form\\[loanFacilityGrid\\]\\[2\\]\\[facility\\]").change( function() {
alert("CHANGE");
} );

Re: Change the defaultvalue property

Posted: Thu Jun 13, 2019 5:45 pm
by amosbatto
JavaScript isn't executed when placed in a subform. You have to put the JavaScript in the parent Dynaform if you want it to execute. If you still can figure it out, then post the .json files for your parent Dynaform and your subforms.

Re: Change the defaultvalue property

Posted: Fri Jun 14, 2019 12:00 am
by kram327
Hi Amos,

Kindly see attachment.

I have tried the code below you have provided in a different thread. It works but I can't edit the values anymore.

Code: Select all
$("#1370990845d01cc5967f945040421865").change( function(e) {
	OMNIBUS(e);
})
  
function OMNIBUS(e) {
	var nRow = $("#GRID_OMNI_FACILITY").getNumberRows();

	for (; nRow >= 1; nRow--) {
  		if ($("#GRID_OMNI_FACILITY").getValue(nRow, 2) == 'Loan Line') {
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_AVAILABILITY\\]").attr("disabled", false);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_TR_TERM\\]").attr("disabled", true);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_FREE_FLOAT\\]").attr("disabled", true);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_TENOR\\]").attr("disabled", true);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_TERM\\]").attr("disabled", true);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_PN_TERM\\]").attr("disabled", false);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_REPAYMENT\\]").attr("disabled", true);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_PRINCIPAL_REPAYMENT\\]").attr("disabled", false);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_INTEREST\\]").attr("disabled", false);
			$("#form\\[GRID_OMNI_FACILITY\\]\\[" + nRow + "\\]\\[OMNI_FX_RATE\\]").attr("disabled", true);
			$("#GRID_OMNI_FACILITY").setValue("Via Peso / Dollar PN", nRow, 7);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 8);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 9);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 10);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 11);
			$("#GRID_OMNI_FACILITY").setValue("Up to ____ days; renewable / extendible for another ____days\n\n\(Note if with assignment, Tenor: Co-terminus with contract date)", nRow, 12);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 13);
			$("#GRID_OMNI_FACILITY").setValue("", nRow, 14);
			$("#GRID_OMNI_FACILITY").setValue("Prevailing SBC lending rate; subject to _____ (monthly or periodic) setting and payment in ____(arrears or in advance)", nRow, 15);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 16);
			$("#GRID_OMNI_FACILITY").setValue('', nRow, 17);
        }
}
}

Re: Change the defaultvalue property

Posted: Fri Jun 14, 2019 6:56 pm
by amosbatto
I don't have time right now. I'll look at on Monday.

Re: Change the defaultvalue property

Posted: Mon Jun 17, 2019 5:15 am
by kram327
Hi Amos,

:D I got it working, but I don't know how to incorporate the first line in your initial recommendation: "var formId = $("form").prop("id");"

4176592055d01e398556d81061810704 is the subform ID


$("#4176592055d01e398556d81061810704").setOnchange( function(fieldId, newVal, oldVal) {
var aMatch = fieldId.match(/^\[GRID_NON_FACILITY\]\[(\d+)\]\[NON_FACILITY\]$/);
if (aMatch) {
var nRow = aMatch[1];
if (newVal == 'TERM LOAN') {
$("#form\\[GRID_NON_FACILITY\\]\\[" + nRow + "\\]\\[NON_FACTOR_RATE\\]").attr("disabled", true);
$("#form\\[GRID_NON_FACILITY\\]\\[" + nRow + "\\]\\[NON_DISCOUNT_CHARGE\\]").attr("disabled", true);
$("#form\\[GRID_NON_FACILITY\\]\\[" + nRow + "\\]\\[NON_SERVICE_CHARGES\\]").attr("disabled", true);

$("#GRID_NON_FACILITY").setValue("For capital expenditures", nRow, 5);
$("#GRID_NON_FACILITY").setValue('', nRow, 6);
$("#GRID_NON_FACILITY").setValue('', nRow, 7);
}
}
});

Re: Change the defaultvalue property

Posted: Mon Jun 17, 2019 1:15 pm
by amosbatto
This line is just to get the ID of the form:
var formId = $("form").prop("id");

but it is better to set the ID in your code if the ID won't change. In your case you should set the ID since you have multiple forms:
var formId = '1234567890abcde1234567890abcde';

Re: Change the defaultvalue property

Posted: Mon Jun 17, 2019 8:24 pm
by kram327
Thanks Amos!
Keep up the good work!
geek