Hi,
To recap: I'm trying to bring the exclamation mark on every NULL field which is marked as required by using the validate function.
If I actually set a value on the field by using editValues, that means I can't check for the isRequired, right?
Also, there's still this problem with the add: it adds 2 rows instead of just 1.
Announcement
Collapse
No announcement yet.
X
-
It looks like what you're doing is setting editValues to exact the current value of the record, which (correctly) is the same thing as not setting an editValue.
To explicitly provide data as though the user had entered it, leave the records blank and provide all the data as editValues only.
Leave a comment:
-
Hello,
I guess I can understand that. I have added the setEditValue as was suggested, also on each existing record. Validate still is not performed on all, however this only results in a correct validation of my last row in the loop the first time after this seteditvalue is called.
Other problem: when I click add to add a row, 2 rows are added to the grid.
Code:/** * Test case to illustrate trying to perform ad hoc validation on a listgrid. * In forms this task is easy to accomplish, in the listgrid this seems not available at all: * * The ValidationClickHandler class tries an adhoc validation per row, using the ListGrid.validateRow funtion. * Documentation of this methods status: <i>This method may also be called directly to perform row level validation at any time.</i> * But it does not seem to work. * * I want to be able to perform ad hoc validation of the entire listgrid because adding a new record does not "constitutes" as a "change" for the listgrid. * It should be able to validate new records, to avoid users from inserting empty lines in the grid. * * / public class AdHocListGridValidation implements EntryPoint { private final ListGrid lgUsers = new ListGrid(); private Button btnAdd = new Button("Add Row"); private Button btnValidate = new Button("Validate"); public void onModuleLoad() { VLayout main = getMainCanvas(); main.draw(); } public VLayout getMainCanvas() { RegExpValidator regExpValidator = new RegExpValidator(); regExpValidator.setExpression("^([a-zA-Z0-9_.\\-+])+@(([a-zA-Z0-9\\-])+\\.)+[a-zA-Z0-9]{2,4}$"); ListGridField[] fields = new ListGridField[4]; fields[0] = new ListGridField("Identification", "Identification"); fields[0].setRequired(true); fields[0].setCanEdit(true); fields[1] = new ListGridField("Signonid", "Signonid"); fields[1].setCanEdit(true); fields[1].setRequired(true); fields[2] = new ListGridField("Password", "Password"); fields[2].setCanEdit(true); fields[2].setRequired(true); PasswordItem item = new PasswordItem(); fields[2].setEditorType(item); fields[2].setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { return "******"; } }); fields[3] = new ListGridField("Email", "Email"); fields[3].setCanEdit(true); fields[3].setValidators(regExpValidator); lgUsers.setFields(fields); lgUsers.setValidateOnChange(true); lgUsers.setShowRowNumbers(true); btnAdd.addClickHandler(new AddClickHandler()); btnValidate.addClickHandler(new ValidateClickHandler()); VLayout main = new VLayout(); HLayout btns = new HLayout(); main.setWidth100(); main.setHeight100(); btns.addMember(btnAdd); btns.addMember(btnValidate); main.addMember(lgUsers); main.addMember(btns); return main; } class AddClickHandler implements com.smartgwt.client.widgets.events.ClickHandler{ public void onClick(ClickEvent event) { ListGridRecord record = new ListGridRecord(); lgUsers.addData(record); int rowNum = lgUsers.getRowNumberStart() + lgUsers.getRecords().length -1; } } class ValidateClickHandler implements com.smartgwt.client.widgets.events.ClickHandler{ public void onClick(ClickEvent event) { int rowNum = lgUsers.getRowNumberStart(); System.out.println("RowNrStart : " + rowNum); for(ListGridRecord rec : lgUsers.getRecords()){ lgUsers.setEditValue(rowNum, "Identification", rec.getAttributeAsString("Identification")); lgUsers.setEditValue(rowNum, "Signonid", rec.getAttributeAsString("Signonid")); lgUsers.setEditValue(rowNum, "Password", rec.getAttributeAsString("Password")); lgUsers.setEditValue(rowNum, "Email", rec.getAttributeAsString("Email")); if(lgUsers.validateRow(rowNum)){ System.out.println("row " + rowNum + ": TRUE"); }else{ System.out.println("row " + rowNum + ": FALSE"); } rowNum++; } } } }
Leave a comment:
-
Data that comes from the server or that you populate via setData() is assumed to be already valid. To have data in the grid treated as though it was user-entered, you can use setEditValues().
Leave a comment:
-
Validate all records in a ListGrid
Hi,
I couldn't find a good example in the showcase, so I made my own.
I want to actively do a validation on all records in the ListGrid, but it seems that validators are only triggered when the user changed the field. For instance, in this example, 3 fields are put required, yet the validator (lgUsers.validateRow(rowNum) -> "This method may also be called directly to perform row level validation at any time" ) do not trigger the "field is required" if the field is still empty.
This is something that works perfectly on forms, but it seems to be hard to do on all ListGrid.
In this example, you can add a record to the grid, fill in Email only and press validate without a validation error on the other fields (not expected).
regardsCode:public class AdHocListGridValidation implements EntryPoint { private final ListGrid lgUsers = new ListGrid(); private Button btnAdd = new Button("Add Row"); private Button btnValidate = new Button("Add Validate"); public void onModuleLoad() { VLayout main = getMainCanvas(); main.draw(); } public VLayout getMainCanvas() { RegExpValidator regExpValidator = new RegExpValidator(); regExpValidator.setExpression("^([a-zA-Z0-9_.\\-+])+@(([a-zA-Z0-9\\-])+\\.)+[a-zA-Z0-9]{2,4}$"); ListGridField[] fields = new ListGridField[4]; fields[0] = new ListGridField("Identification", "Identification"); fields[0].setRequired(true); fields[0].setCanEdit(true); fields[1] = new ListGridField("Signonid", "Signonid"); fields[1].setCanEdit(true); fields[1].setRequired(true); fields[2] = new ListGridField("Password", "Password"); fields[2].setCanEdit(true); fields[2].setRequired(true); PasswordItem item = new PasswordItem(); fields[2].setEditorType(item); fields[2].setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { return "******"; } }); fields[3] = new ListGridField("Email", "Email"); fields[3].setCanEdit(true); fields[3].setValidators(regExpValidator); lgUsers.setFields(fields); lgUsers.setValidateOnChange(true); lgUsers.setShowRowNumbers(true); btnAdd.addClickHandler(new AddClickHandler()); btnValidate.addClickHandler(new ValidateClickHandler()); VLayout main = new VLayout(); HLayout btns = new HLayout(); main.setWidth100(); main.setHeight100(); btns.addMember(btnAdd); btns.addMember(btnValidate); main.addMember(lgUsers); main.addMember(btns); return main; } class AddClickHandler implements com.smartgwt.client.widgets.events.ClickHandler{ public void onClick(ClickEvent event) { ListGridRecord record = new ListGridRecord(); lgUsers.addData(record); } } class ValidateClickHandler implements com.smartgwt.client.widgets.events.ClickHandler{ public void onClick(ClickEvent event) { int rowNum = lgUsers.getRowNumberStart(); System.out.println("RowNrStart : " + rowNum); for(ListGridRecord rec : lgUsers.getRecords()){ if(lgUsers.validateRow(rowNum)){ System.out.println("validaterow " + rowNum + " TRUE"); }else{ System.out.println("validaterow " + rowNum + " FALSE"); } rowNum++; } } } }
SmartGWT LGPL 2.3Tags: None
Leave a comment: