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 HeshanKaru1994
#824434
I have two controls inside a grid.
1)Dropdown
2)Text box

If the selected value of dropdown is True then the text field should be disabled otherwise text field should be required, there are many rows in the grid that loaded from a trigger
User avatar
By amosbatto
#824613
HeshanKaru1994 wrote: Mon May 27, 2019 3:17 am How to make sure the dropdown has values and selected an option from the dropdown
You can use JavaScript like this:
Code: Select all
var gridId = "productsList";        //set to ID of grid
var valueToCheckId = "inStock";     //set to ID of grid field whose value will be checked to disable or require 
var valueToCheckColNo = 1           //set to column number of grid field whose value will be checked. Counting starts from 0.
var requiredId = "quantityInStock"; //set to ID of grid field to disable or require
var requiredColNo = 2;              //set to column number of grid field to disable or require. Counting starts from 0.

var aGridVals = $("#"+gridId).getValue();
var reGridField = RegExp("^\\["+gridId+"\\]\\[(\\d+)\\]\\["+valueToCheckId+"\\]$");
var formId = $("form").prop("id");
var aGridTable = getFieldById(gridId).gridtable;


function setGridField(valueToCheck, rowNo) {
  //"True" is the value of a selected option in grid's dropdown:
  if (valueToCheck == "True") {    
    $("#form\\["+gridId+"\\]\\["+rowNo+"\\]\\["+requiredId+"\\]").prop("disabled", false);
    getFieldById(gridId).gridtable[rowNo-1][requiredColNo].enableValidation();
  }
  else if (valueToCheck == '' || aGridTable[rowNo-1][valueToCheckColNo].getInfo().options.length == 0) {
    //not sure what you want to do here:
    alert("No option selected in row "+rowNo+".");
  }
  else {
    $("#form\\["+gridId+"\\]\\["+rowNo+"\\]\\["+requiredId+"\\]").prop("disabled", true);
    getFieldById(gridId).gridtable[rowNo-1][requiredColNo].disableValidation();
  }
}

//set the field in each row in the grid when the Dynaform loads:
for (var i = 0; i < aGridVals.length; i++) {
  setGridField(aGridVals[i][1], i+1); //add 1 because counting starts from 0.
}

//when a value changes in the form:
$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
  var aMatch = fieldId.match(reGridField);
  
  if (aMatch) {
    setGridField(newVal, aMatch[1]);  
  }
});  

$("#"+gridId).onAddRow( function(aNewRow, oGrid, rowIndex) {
  var val = aNewRow[valueToCheckColNo].getValue();
  setGridField(val, rowIndex);
});
By HeshanKaru1994
#824623
.............................................................................................................................................................................................
<select id="form[dropdown0000000001]" name="form[dropdown0000000001]" class="pmdynaform-control-dropdown form-control">
<option value="2" >FINANCE</option>
<option value="3">MARKETING</option>
</select>
<input type="hidden" value="HR" id="form[dropdown0000000001_label]" name="form[dropdown0000000001_label]">
<span class="content-print">HR</span>
.............................................................................................................................................................................................
I have only 3 departments in the dropdown. The problem is I am starting a case with "HR" and without submitting I am saving It as a draft.As you can see it sets the input as "HR". But then I start a new case with "HR" and submits it. Then I have only 2 values in the dropdown(Using PM tables I am checking which departments have been used)
Then I can submit a case with "HR" since the hidden variables store the value when it was drafted.How to stop such scenario
User avatar
By amosbatto
#824641
HeshanKaru1994 wrote:I have only 3 departments in the dropdown. The problem is I am starting a case with "HR" and without submitting I am saving It as a draft.As you can see it sets the input as "HR". But then I start a new case with "HR" and submits it. Then I have only 2 values in the dropdown(Using PM tables I am checking which departments have been used)
Then I can submit a case with "HR" since the hidden variables store the value when it was drafted.How to stop such scenario
Stop what scenario? It is not clear to me what you are trying to prevent.
generate daily excel report

I have exported table into excel sheet as shown in[…]

Please replay if there is any solution!!!!

Task doesnt have any users.

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

Just guide me to implement this?