Aca es un ejemplo de un DynaForm que puedes importar para ver como implementar esto:
(3.02 KiB) Downloaded 347 times
En este ejemplo, tienes un grid con la ID "productsGrid", que contiene 2 campos:
- un dropdown con la ID "productType" que tiene 3 opciones:
--- "virtual"
--- "manufactured"
--- "out-sourced"
- un textbox con la ID "productName"
Si el usuario selecciona "virtual" en el dropdown "productType", el campo "productName" sera deshabilitado.
Este es el codigo de JavaScript en el DynaForm:
Code: Select allvar gridId = "productsGrid"; //set to the ID of the grid
var nRows = $("#"+gridId).getNumberRows()
$("[id='form["+gridId+"]["+i+"][productName]']").prop("disabled", true);
// enable/disable "productName" textbox in any existing rows when the form loads:
for (var i = 1; i <= nRows; i++) {
var productType = $("#"+gridId).getValue(i, 1);
if (productType == 'virtual') {
$("[id='form["+gridId+"]["+i+"][productName]']").prop("disabled", true);
}
else {
$("[id='form["+gridId+"]["+i+"][productName]']").prop("disabled", false);
}
}
function disableProductName(fieldId, newVal, oldVal) {
var aMatches = fieldId.match(/^\[productsGrid\]\[(\d+)\]\[productType\]$/);
//if a value is changed in the "productType" field in the "productsGrid":
if (aMatches) {
var row = aMatches[1];
if (newVal == 'virtual') {
$("[id='form["+gridId+"]["+row+"][productName]']").prop("disabled", true);
}
else {
$("[id='form["+gridId+"]["+row+"][productName]']").prop("disabled", false);
}
}
}
$("form").setOnchange( disableProductName );
$("#"+gridId).onAddRow(function(aNewRow, oGrid, rowIndex) {
disableProductName("["+gridId+"]["+rowIndex+"][productType]", aNewRow[0].getValue(), '');
});