Hi levi,
Earlier you faced some problem and solved.
When clicking on validate button 2 records are addding.
now im also having the same issue.
I just want to know how to validate with existed records.
validations are coming properly but new records are coming that is only
my issue. can you help me to do this.
Thanks in Advance
Announcement
Collapse
No announcement yet.
X
-
Hi
Isomorphic and levi,
im using levi's code which was there under validate button. But still im getting
below error.
when clicking on validate button new records adding with validations.
But here i dont want to add new records.
I just want to validate with existed records.
Below is my code:
int rowNum = secDBDeviceListGrid.getRowNumberStart();
System.out.println("RowNrStart : " + rowNum);
for(ListGridRecord rec : secDBDeviceListGrid.getRecords()){
secDBDeviceListGrid.setEditValue(rowNum, "First", rec.getAttributeAsString("First"));
secDBDeviceListGrid.setEditValue(rowNum, "Second", rec.getAttributeAsString("Second"));
rowNum++;
secDBDeviceListGrid.startEditingNew();
}
Here im not able find where i did mistake.
Thanks in advance.
Leave a comment:
-
Cavaleiro's solution seems to validate null fields.
I ran into the same problem reported in this topic: I have some data entered by the user via an edit box, and then I display it on ListGrid, so when I add it to the ListGrid it is effectively user-entered data, and needs to be validated, but the ListGrid does not validate it because it assumes that data added/updated via addData () / updateData () has already been validated.
I tried using startEditing () /startEditingNew () / endEditing () with no luck:
1. The first record of the ListGrid appeared to be blue in color
2. The most recent record added would show edit boxes but no errors
So I went back to basics and just added a method that I could simply call to validate all the data on the ListGrid after I load it. I added these methods to my ListGrid class which extends com.smartgwt.client.widgets.grid.ListGrid:
To use it:Code:/** * Validates all rows/cells whether they were entered by the user or added via addData (); * Returns true if validation was successful (no errors encountered), false otherwise * See http://forums.smartclient.com/showthread.php?t=13223&page=2&highlight=listgrid+validate * @return boolean */ public boolean forceValidate () { // iterate all rows of data boolean sucessFlag = true; final ListGridField[] listGridFieldArray = super.getFields (); final int recordCount = getRecordCount (); for (int rowIndex = 0; rowIndex < recordCount; rowIndex ++) { // iterate all fields for this row final Record record = super.getRecord (rowIndex); for (final ListGridField listGridField : listGridFieldArray) { // acquire current value final String fieldName = listGridField.getName (); final String value = record.getAttributeAsString (fieldName); // change the cell value to some base value super.setEditValue (rowIndex, fieldName, "abc123ABC456!!!"); super.validateCell (rowIndex, fieldName); // set the cell value to the original value forcing ListGrid to detect a change, then validate it super.setEditValue (rowIndex, fieldName, value); final Boolean validateFlag = super.validateCell (rowIndex, fieldName); if (validateFlag != null && validateFlag.equals (Boolean.FALSE)) { sucessFlag = false; } } } // done return sucessFlag; } /** * Validates all rows/cells * Returns true if validation was successful (no errors encountered), false otherwise * Inline with other SmartGWT components, this validates ONLY data entered by the user * See forceValidate () if you want to validation independent of whether the user entered * the data, or it was handled programmatically via addData () / updateData () * @return boolean */ public boolean validate () { // iterate all rows boolean sucessFlag = true; final int recordCount = getRecordCount (); for (int rowIndex = 0; rowIndex < recordCount; rowIndex ++) { // validate this row final Boolean validateFlag = super.validateRow (rowIndex); if (validateFlag != null && validateFlag.equals (Boolean.FALSE)) { // validate for this row failed: track sucessFlag = false; } } // done return sucessFlag; }
I just coded these methods in the last few days so I am not sure that they are 100% correct, but they seem to work so far...Code:final ListGrid listGrid = new ListGrid (); listGrid.setWhatever (); listGrid.addData (records...); listGrid.forceValidate ();
Leave a comment:
-
For those who still have problem with record/cell validation and all the submitted suggestions doesn't fit, here is a work around:
I assume that this "problem" is not a limitation of the framework but it will be handy if a "forceValidateRow()" or something else could be available in one of the next releases of smartgwt.Code:private boolean validateRecordRequiredFields(final ListGridRecord record, final List<ListGridField> requiredFields) { int size = requiredFields.size(); for (int i = 0; i < size; ++i) { ListGridField lgf = requiredFields.get(i); String fieldName = lgf.getName(); if (record.getAttribute(fieldName) == null) { Integer recordIdx = lgTable.getRecordIndex(record); lgTable.setEditValue(recordIdx, fieldName, "null"); lgTable.validateCell(recordIdx, fieldName); lgTable.setEditValue(recordIdx, fieldName, ""); lgTable.validateCell(recordIdx, fieldName); return false; } } return true; }
Regards,
Cavaleiro.Last edited by Cavaleiro; 18 Jan 2012, 04:55.
Leave a comment:
-
This is not an unusual use case and we use this approach routinely. Something is wrong in your code, and if you want help with it, you should put together minimal code that we can run to see one of the problems you're having.
Leave a comment:
-
Are you referring to ListGrid? I specifically changed my code to use TreeGrid but it still doesn't work. Btw. I do not use paging.Originally posted by IsomorphicYou can use just add() but the new node will always be at the end of the dataset. This is because of how complex it would be to do paging when the client is trying to keep track of newly added rows that the server doesn't know about.
I was able to add nodes to ListGrid group before I switched to TreeGrid. Now I did both of the above strategies and I am able to add nodes under parent node I want. But it is not the core problem.Originally posted by Reference page, on TreeGrid.startEditingNew()This inherited ListGrid API is not supported by the TreeGrid since adding a new tree node arbitrarily at the end of the tree is usually not useful. Instead, to add a new tree node and begin editing it, use either of these two strategies:
1. add a new node to the client-side Tree model via Tree.add(), then use startEditing to begin editing this node. Note that if using a DataSource, when the node is saved, an "update" operation will be used since adding a node directly to the client-side ResultTree effectively means a new node has been added server side.
2. use DataSource.addData() to immediately save a new node. Automatic cache sync by the ResultTree will cause the node to be integrated into the tree. When the callback to addData() fires, locate the new node by matching primary key and call startEditing to begin editing it.
The problem was there with ListGrid and with TreeGrid is still there. Validators do not work properly. This is definitely a bug! I'm stuck with this issue for more than a month now...
I'm adding nodes where I want but VALIDATORS do not show up.
Recently I tried this code:
Your advice on setEditValues didn't work. Only two methods setEditValues and validateRow used simultaneously made validators to actually show up. But that's not the end... When I double click on some empty cell and then exit the editor *LEAVING EMPTY VALUE* then ALL validators on all fields DISSAPEAR!Code:ds.addData(newRecord, function(dsResponse, data, dsRequest) { var obj = grid.data.findById(newRecord.id); var rowNum = grid.getRecordIndex(obj); grid.setEditValues(rowNum, newRecord); grid.validateRow(rowNum); });
I'm enough frustrated with this... Please add some nodes with invalidate fields to treegrid and see it for yourself.
Leave a comment:
-
You can use just add() but the new node will always be at the end of the dataset. This is because of how complex it would be to do paging when the client is trying to keep track of newly added rows that the server doesn't know about.
Leave a comment:
-
I don't know primary key because it is assigned on the server side. Also I don't want to add empty records to the database.
Why it is not possible with grid.data.add()? In regular ListGrid, validation is performed on each record added with startEditingNew() function. And that works *before* data is submitted to the server.
Currently I tried this code, but it doesn't show validators:
Code:var id = ... // id of the parent node var parentNode = grid.data.findById(id); var treeNode = grid.data.add({parentId:id}, parentNode); var rowNum = grid.getRecordIndex(treeNode); newValues.parentId = id; grid.setEditValues(rowNum, newValues);
Leave a comment:
-
If you need the node at a particular spot, use addData() to create the new node with just a primaryKey and foreign key (so it appears in the right spot in the tree) then after it is saved (use callback from addData()) use setEditValues to apply values you want validated as though they were user input.
Leave a comment:
-
The same problem still remains in TreeGrid where startEditingNew is not a good way to add rows because they are added at end of the list.
Documentation says that the better way is to add TreeNode by using grid.data.add() but when I do this I end up with the same problem as original poster had. The newly added row is not validated.
I tried adding empty {} data to particular parent node and then calling setEditValues(). This way I got one row validated but after adding more rows only the last one display exclamation marks on required fields. This is the same as on val2.png screenshot attached by original poster.
What should I do to add new rows to the TreeGrid so their fields get validated? I need the same functionality as startEditingNew() but with possibility to insert new row under some parent node.
Leave a comment:
-
You're adding a row via addData() - this means the new row is saved, and then provided to the grid via cache sync as an already-valid row that exists as part of saved data.
Instead, use startEditingNew() to add a new row that is considered user-provided data.
See the ListGrid Editing Overview for further context.
Leave a comment:
-
Hi,
It doesn't concern validation of existing data that is used to populate the grid.
It concerns valdiation of mandatory fields in a listgrid. If these fields are not edited, no automatic validation is triggered
==> it should be possible to trigger the validation manually + validation should fail if no value is in the mandatory field.
CASE:
1. User adds row via AddRow which creates an empty row in listgrid (some fields in that row are set mandatory)
2. User presses the save , no validation ever occurred and data is saved
==> NOK
During save we want to trigger the validation of these rows, however it seems imposssible to do this. I have implemented the last suggestion, but doesn't work either. Mind I do NOT use a datasource.
(In the example I try validating all rows, actually only the added rows must be validated)
With the modified sample,
I get following issues:
Issue 1. First time I press addRow : 2 rows are added.
(screenshot 1)
Issue 2. I add 3 more rows and then press validate: only the last row in the loop is actually validated.
(screenshot 2)
The log of the validate loop (only knows of 4 rows , probably issue with the two rows that were added during first add, are not "really added" both, but only 1) (See previous post for the code):
RowNrStart : 1
row 1: TRUE
row 2: TRUE
row 3: TRUE
row 4: FALSE
=> NOK , the exclamation mark should be there in all rows.
How can I achieve this?
thanks for the ideas
Leave a comment:
-
If the new value is null, don't call setEditValue() for that field, and if there's no value in the record, it will be flagged as a validation error if the field is required.
Don't call addData() to get the data into the grid - that's going to try to save data back to the DataSource. The initial data (blank rows except for primary key values presumably) can be provided as a RecordList or ResultSet, each easy to retrieve using DataSource.fetchData(), and then editValues can be overlaid on this.
Leave a comment:
Leave a comment: