-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to check is all editor value in dgrid are valid?? #196
Comments
None that I know of. What I did was something like this after saving object ids of new rows: |
I had same issue I ended up Wrapping the dgrid as Widget and added the next APIs:
|
I had a similar issue where I wanted my encapsulating dijit.form.Form to be able to validate my widgets within a dgrid when calling (for example) myDijitForm.validate() so that the widgets within the dgrid will get the focus/tooltip if they are the first invalid element in the form. Here was my solution (using Dojo 1.7 with dgrid 0.3.5-dev):
<div data-dojo-attach-point="containerNode">
<div data-dojo-attach-point="dgrid"></div>
</div>
getChildren: function() {
var children = [];
var myWidgetCell = null;
array.forEach( this.store.query({}), lang.hitch( this, function( data ) {
myWidgetCell = this.grid.cell( data.id, 'columnName' );
children.push( myWidgetCell.element.widget );
} ) );
return children;
}
Sorry for the lack of comprehensive code samples. There is probably a more complete/concise way to do this, but I fought with this for a couple days. I definitely think dgrid widgets should be accessible to encapsulating forms by default, but hopefully this helps anyone having similar issues! |
This direction can benefit next issue I checked: |
validate: function() {
var grid = this;
var dirty = grid.dirty;
var store = grid.store;
var colsMap = {};
var cols = this.columns;
for(colId in cols) {
var col = cols[colId];
if(col.field) {
colsMap[col.field] = {col: col, colId: colId};
}
}
var datas = grid.store.query(grid.get("query"), grid.get("queryOptions"));
var isValid = true;
for(var i=0; i<datas.length; i++) {
var data = datas[i];
var id = store.getIdentity(data);
for(field in colsMap) {
var colDef = colsMap[field];
var cell = grid.cell(id, colDef.colId);
var value = (grid.dirty && grid.dirty[id] && grid.dirty[id][field]) || data[field];
var column = cell.column;
if(column.canEdit && column.canEdit(data, value)) {
//shared editorInstance, editor TODO
var editor = column.editorInstance;
if(editor && editor.get) {
var oldValue = editor.get("value");
editor.set("value", value);
//check
var isCellValid = editor.validate();
if(!isCellValid) {
grid._inValidCell(cell.element);
isValid = false;
}
editor.set("value", oldValue);
}
}
}
}
return isValid;
} |
In the above reference, I find another way that works for me after countless trials. ......
var cell = grid.cell(rowId, colDef.colId);
var valid = cell.element.widget.isValid();
if (!valid) {
TODO:
}
...... element is a useful object |
I put a dgrid inside a form. When user click submit button the dgrid.save() will be trigger.
I know that the dgrid.save() function will ignore all the invalid value in editor.
But what I want is when user click submit, if there are any editor's value is invalid then the submission will stop and warn the user.
So are there any dgrid.isValid() function?
The text was updated successfully, but these errors were encountered: