- Tue Oct 06, 2020 2:13 am
#828514
Hello friends
I want to disable a text box using the drop-down list
But this code does not work and just disables but can not activate
I want to disable a text box using the drop-down list
But this code does not work and just disables but can not activate
Code: Select all
https://www.pmusers.com/index.php/Enable_or_disable_fields_in_grid//when the Dynaform loads, pass through the grid and disable or enable the discountRate field
//in each row, depending on the value of the hasDiscount field.
var nRows = $("#equipmentList").getNumberRows();
for (i = 1; i <= nRows; i++) {
var hasDiscount = $("form\\[equipmentList\\]\\["+i+"\\]\\[hasDiscount\\]").val();
if (hasDiscount == "Discount") {
$("#form\\[equipmentList\\]\\["+i+"\\]\\[discountRate\\]").prop("disabled", false);
}
else { // if "No Discount":
$("#form\\[equipmentList\\]\\["+i+"\\]\\[discountRate\\]").prop("disabled", true);
}
}
//when a new row is added to the grid, disable the discountRate field by default.
$("#equipmentList").onAddRow( function(aNewRow, oGrid, rowIndex) {
$("#form\\[equipmentList\\]\\["+rowIndex+"\\]\\[discountRate\\]").prop("disabled", true);
});
var formId = $("form").prop("id");
//Set an onchange event handler for the form. When the value of a field changes in the Dynaform,
//check whether the changed field is the hasDiscount field in the grid.
//If so, then if hasDiscount is set to "Discount", then enable the discountRate field in the same row.
//If set to "No Discount", then disable the discountRate field.
$( "#" + formId ).setOnchange( function(fieldId, newVal, oldVal) {
//check if a field changed inside the grid:
var aMatches = fieldId.match(/^\[equipmentList\]\[(\d+)\]\[hasDiscount\]$/);
if (aMatches) {
var rowNo = aMatches[1];
if (newVal == "Discount") {
$("#form\\[equipmentList\\]\\["+rowNo+"\\]\\[discountRate\\]").prop("disabled", false);
}
else { // if (newVal=="No Discount"):
$("#form\\[equipmentList\\]\\["+rowNo+"\\]\\[discountRate\\]").prop("disabled", true);
//delete the existing value in the discountRate field:
$("#form\\[equipmentList\\]\\["+rowNo+"\\]\\[discountRate\\]").val("");
$("#form\\[equipmentList\\]\\["+rowNo+"\\]\\[discountRate_label\\]").val("");
}
}
});