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).
regards
SmartGWT LGPL 2.3
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).
Code:
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.3
Comment