Un foro de discusión para nuestra comunidad de hispano hablante
By alfonsotesys
#790467
Buen día espero me puedan ayudar, tengo un grid en el cual tengo un combo y un textbox cuando e selecciona una opcion en particular del combo de ese renglon tengo que habilitar o des habilitar el texbox de ese renglon, alguien sabe como hacer esto, en javascript?

Saludos y de antemano gracias
User avatar
By amosbatto
#790516
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 all
var 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(), '');
});
By alfonsotesys
#790536
amosbatto wrote:Aca es un ejemplo de un DynaForm que puedes importar para ver como implementar esto:
Disabling fields in grids.json
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 all
var 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(), '');
});
Muchas gracias por la respuesta lo voy a aplicar, Gracias y salidos
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]