-
10 Mar 2011 6:15 AM #11
updateRecord will work for me for the values. It's not automatic. But I suppose I could live with that aspect.
Anybody know at this point in time what the validation rules on the model are good for? I looked at
loadRecord for Forms and I don't see it doing anything with the validation rules. I am starting
to get a little disappointed. I had this whole architectural idea of using reflection
on my server's CSLA business object layer to dynamically create a ExtJS model protoype with validation rules.
It was going to be real cool. But I don't see any of the UI using the validation on the model.
I am hoping a Sencha developer can correct me and show me where I am going wrong.
Thoughts?
-
10 Mar 2011 6:24 AM #12Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
There is no automatic, bidirectional updating from Model < - > Form. You need to use loadRecord to load a record (model instance) into the form and then when you save the form, you will need to update the record that you loaded via basicForm.updateRecord(rec)
As for validations, that is for if you try to update/create a record. If it passes the validation, it will return no errors. If there are errors, it will return an Ext.data.Errors object. Love this approach. More robust than just using vtypes and allowBlank.Code:/** * Persists the values in this form into the passed {@link Ext.data.Model} object in a beginEdit/endEdit block. * @param {Ext.data.Record} record The record to edit * @return {Ext.form.Basic} this */ updateRecord: function(record) { //record.beginEdit(); var fields = record.fields, values = this.getValues(), name, obj = {}; fields.each(function(f) { name = f.name; if (name in values) { obj[name] = values[name]; } }); record.set(obj); //record.endEdit(); return this; },
So on saving you can do this:
Code:var basicForm = this.getForm(), rec = this.rec; basicForm.updateRecord(rec); var success = rec.validate().isValid(); if (success) { //handle success } else { //handle failure }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Mar 2011 6:31 AM #13
Ok that sounds good, but how do I use this "errors object" that returns from the model to show up in the UI?
To me that would be very important in using the validation logic on the model (because this is all pretty much just client side type of validation anyway).
-
10 Mar 2011 6:35 AM #14
Ahh I think I found it on basic form... markInvalid(..)
Ok, I am starting to feel better again
Would be nicer if it was all automatic like .NET... But I can live with this.
-
10 Mar 2011 6:37 AM #15Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Yes, you should not 100% rely on JS code but for 99% of users aren't hackers. Weird things happen so even though only 1% of users may have bad intent, something funky can go wrong for the 99% of people.
Anyway, the API docs for Ext.data.Errors has a pretty good example:
All the Ext.data.Errors is is an instance of MixedCollection. Notice that when you getByField("..."), it returns an array. This tripped me up.Code:var errors = myModel.validate(); errors.isValid(); //false errors.length; //2 errors.getByField('name'); // [{field: 'name', error: 'must be present'}] errors.getByField('title'); // [{field: 'title', error: 'is too short'}]Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Mar 2011 6:38 AM #16Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Mar 2011 6:41 AM #17
I agree when I code I assume anything coming into my server is hostile and should not be trusted. The client side validation is just a "nicety" for the UI. All it takes is some kid to use a JS debugger and you are in trouble unless you protected the server.
-
10 Mar 2011 6:44 AM #18Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
10 Mar 2011 6:48 AM #19
Lol, I wish I had that problem! I do code however for that day

-
10 Mar 2011 7:13 AM #20
I want each field to validate itself on focus out. No point in getting people all the way down to the save button just to tell them a client side rule failed. I suppose I could hook validating the model on every focus out event?
Similar Threads
-
[FIXED] Selection Model Binding Problem When Using Multiple Grids
By j-joey in forum Ext Designer: BugsReplies: 5Last Post: 15 May 2012, 8:06 PM -
Form Binding to BeanModel
By zathril in forum Ext GWT: DiscussionReplies: 0Last Post: 28 Mar 2010, 1:08 PM -
Form binding / update model
By tsegismont in forum Ext GWT: Help & Discussion (1.x)Replies: 0Last Post: 2 Apr 2009, 1:22 AM -
Form binding
By exo in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 16 Apr 2007, 4:20 AM


Reply With Quote