cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a cell mandatory in sap.ui.table?

Former Member
0 Kudos
971

Hi,

I have used sap.ui.table with one label , 2 textbox and checkbox enable(using sapUiSizeCozy css) now i have a requirement like when a row is selected then the corresponding text box shld be mandatory... i didnt assign id to each cell.. instead i hav used a model variable to values for textbox.. how wil i get the value of textbox and assign validation(setvaluestate=error) when checkbox are selected and values in textbox is empty? onselection of checkbox how to retrieve values of textbox in the row??

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hello,

Define the below property for table,

selectionBehavior: sap.ui.table.SelectionBehavior.Row,

rowSelectionChange event will be triggered upon clicking anywhere on the row. Implement your code under this event.

tableo.getSelectedIndex() will get the index of the row.


Once you get the rowindex its easy to get the entire row data by using

var rowdata = tableo.getContextByIndex(tableo.getSelectedIndex());

after getting the rowdata, use rowdata.getProperty("<give the field name of the model to which the textbox binding is performed");

this would return the value of the textbox.

Thanks.

Former Member
0 Kudos

Hi,

Thanks for sharing this info.. using these steps i can get the value of textbox.. but how will i make textbox in particular row as mandatory when checkbox is checked.. Please suggest some ideas

0 Kudos

Hi,

Probably, inside the rowSelectionChange event,

Check oCheckbox.getChecked(). It return a boolean. Put it in If condition

if(){

//True block

check the value of textbox, if it is blank - oTextfield.setValueState("Error");

}

else{
//False block

}

If you are trying to insert/delete/edit data:

in button press event,

var textVal = oTextfield.getValue();

if(oCheckbox.getChecked() && textVal != ""){

//This block gets executed when the checkbox is checked and Textfield has some value

}

else{

//Show message to say textfield is mandatory

sap.ui.commons.MessageBox.alert("Textfield can not be blank");

}

This would hopefully meet your requirement.

As a beginer of SAP UI5, i can not think of a better solution than this. May be, you could await an expert suggestion.

Thanks