How to get reactors on grid rows?

3 views
Skip to first unread message

murrayh...@gmail.com

unread,
Jul 16, 2015, 3:11:32 AM7/16/15
to gl...@googlegroups.com
Hi.

Well, I am making great progress with GluJS and liking it more and more.

I have a grid populated with RowModels. The grid has a row editor which is all working properly. I need validation on the fields in the row and figure that that is what the formulas property of the RowModel config is for? But how do I set that up please?

My model is like this:

glu.namespace('App.glu.models').UserCfg = {
idProperty : 'userid',
proxy : {
type:'rest',
url:'http://127.0.0.1:8501/sites/blah/blah/user',
reader:{
type : 'glujson',
root : 'user',
totalProperty : 'totalcount'
}
},

fields:[
{ name: 'userid', type:'int' },
{ name: 'username', type: 'string'},
{ name: 'firstname', type: 'string'},
{ name: 'lastname', type: 'string' }
// etc
]
};

var rowModel = glu.deepApply({
formulas:{
// Something here??
}
},App.glu.models.UserCfg);

glu.defRowModel('App.glu.models.User',rowModel);

and the viewModel that references the store containing that model is like this:

glu.defModel('App.glu.UserList',{

UserList : {
mtype : 'glustore',
model : 'App.glu.models.User',
autoSync : true,
remoteSort : true,
remoteFilter: true,
pageSize : 20,
sorters : [{property:'username'}]
}
// etc
});

So, imagine a simple validator like:
usernameIsValid$:function () {
var fld = this.get('username');
var valid = (fld.length >= 6); // simple test
return valid ? true : this.localize('err_username');
}

Where do I put that so that when the rowEditor is editing a row, the usernameIsValid$() function on that row is called to get the valid state?

Looking at the code I can see the usernameChanged() function gets added if I include it in the config formulas object, but no IsValid reactors, nor a way I can see to define them.

Thanks again,
Murray



Ryan Smith

unread,
Jul 20, 2015, 12:28:42 PM7/20/15
to gl...@googlegroups.com
Hey Murray,

I was hoping that someone else might be able to chime in on this.  I haven't ever done any validation on grid row editors like you are talking about.  All of my grids have been non-editable, or if they were editable it wasn't going to be something that really needed validation like you are talking about.  Its unlikely that you would need a "forumlas" object for glujs though... that was a Sencha construct with their newer versions.  In theory you should be able to write the formulas just like any other viewmodel with something like usernameIsValid$.  If I had to guess, the usernameChanged event is coming from Sencha?  I'm going to stop guessing at this point though :(.  If you want to send over some sample code I could take a look at it... otherwise you've moved into territory that is un-charted :).  Good Luck!!

-Ryan

--
You received this message because you are subscribed to the Google Groups "GluJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glujs+un...@googlegroups.com.
To post to this group, send email to gl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glujs/97225504-e640-4473-941f-f05bf050bbfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

murrayh...@gmail.com

unread,
Jul 20, 2015, 4:10:28 PM7/20/15
to gl...@googlegroups.com
Thanks Ryan. I thought that since it was mentioned in the source it must have been Glu related:

* @class glu.RowViewmodel
* An extremely lightweight version of a view model that just has formulas (for now).
* Very useful to get reactive behavior in grids where items can automatically update without a grid refresh
* or based on other columns locally changing.
* Available (at the moment) only for Ext 4.x +

I will work out how to map the Ext roweditor form to the Glu viewmodel validation process.

Cheers,
Murray

Reply all
Reply to author
Forward
0 new messages