Disable textbox based on dropdown value in a table

Hi,

I have a table in that 1st column is a dropdown and second column is a textbox. This textbox should be disabled in case of a particular value. How can I achieve this? As this is a table I am finding it difficult.

Thanks.
Sanket

1 Like

Hi Sanket,

You can try with addRowChangeListener of table in Script Block.

Please try if the below code works.


CAF.model('#{activePageBean.clientIds["tableID"]}').addRowChangeListener(
  function(id, rowId, type) {
  if (type != 'select') {
        return;
    }
	var prevRowState=CAF.model('#{activePageBean.clientIds["rowId"]}');
	var prevRowModel =CAF.model(prevRowState.getValue()); 
	var prevButtonId = prevRowModel.getControlId("drpDownID");
var prevButtonModel = CAF.model(prevButtonId); 
var prevButtonId1 = prevRowModel.getControlId("testBox");
var prevButtonModel1 = CAF.model(prevButtonId1); 
if(prevButtonModel=='xyz')
{
prevButtonModel1..setDisabled(true);
}
}

This is not a tested code.Please try and let know if you are facing any issue.

Thanks
Baharul Islam

Hi Baharul,

Thanks for your reply. I am completely new to CAF.

I have copy pasted this code and used it in a script block. Iā€™ve tried placing the script block both outside the table and inside the table, but it is not working.

I am having an asyn table which is loading data from db and there is a third column which is having add row and remove row button. So If a user clicks add row then a new row is added with the above mentioned columns dropdown and textbox. One of the req is to disable the 2nd column textbox based on value of the dropdown from the 1st column of the same row.

2nd req is to populate the textbox based on value in the dropdown. This i am able to achieve using hidden async command and raise on change controls, wherein i am calling a service when dropdown changes and setting the output to the textbox and refreshing it. However, the problem here is when a user clicks add row and changes the dropdown value and when the async hidden command refreshes the textbox. The newly added rows textbox dissapears. :frowning:

Can you please help me. Thanks again

Hi TeKnAs,

I have done one sample poc for the same.Please check if this is what you are looking for.
From archive project use ā€œTableā€ portlet one.

Please let us know for any confusion.

Thanks
Baharul Islam

Attaching the file
CAF_Testing.zip (27.3 KB)

1 Like

Thank you Baharul, for your help. :slight_smile: