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 allvar 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);
});