-
10 Mar 2011 7:16 AM #21Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 434
When you create the form, create a blank model instance. Then listen to the field's blur event and set that value to the field in the model instance. Then validate and getByField to see if it's valid.
Not sure if that will work but it should
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 9:23 AM #22
You guys doing a Form.markInvalid and getting it to display errors on the form? Mine is not. Debugging shows there are errors but no red squigglies...
PHP Code:this.deviceCoverage.getForm().updateRecord(this.deviceCoverageRecord);
var errors = this.deviceCoverageRecord.validate();
if (!errors.isValid()) {
this.deviceCoverage.getForm().markInvalid(errors);
return;
}
-
10 Mar 2011 9:26 AM #23Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 434
I haven't tried it but your code could be cleaned up a bit, don't take this the wrong way...
Code:var me = this, form = me.deviceCoverage, basic = form.getForm(), rec = me.deviceCoverageRecord; basic.updateRecord(rec); var errors = rec.validate(); if (!errors.isValid()) { basic.markInvalid(errors); return; }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 9:40 AM #24
I noticed that Ext JS 4 uses var me = this; What is the reason behind doing this?
-
10 Mar 2011 9:44 AM #25Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 434
- Cuts down 2 characters per reference after the length of the line that creates the 'me' variable
- Minifies better
Sure there are other reasons. I have talked to Jay Garcia and Ed Spencer about it one day and this is what we decided. It's agreed that we don't like it. Only reason I don't is because the IDE (BBEdit) I use highlights 'this' as blue. May be able to do it with 'me' but I'm too lazy.
You don't always need to do
On listeners, you can do it.Code:var me = this;
Code:listeners: { afterrender: function(grid) { var me = grid; } }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 10:15 AM #26
So debugging the code shows markInvalid wants 'id' and 'msg' but errors.items contains 'field' and 'message'. It appears to be the same data just with different field names. So is the best solution to iterate over errors.items and build a new object with the desired names? Easy to do but will get repetitive for all form validation. I would think that if a form uses a model, it should be able to understand the model's errors.
Maybe I'm missing something?
-
10 Mar 2011 3:14 PM #27
I know this got a little off-topic but back to the "me" code style. Is what I did below:
var nextButton = me.nextButton = <object> taking it too far for object creation?
Code:index: function(options) { var me = this, app = me.application; if (!options.back) { me.deviceCoverage = Ext.create('Prepaid.views.DeviceCoverage', {}); me.deviceCoverageRecord = Ext.ModelMgr.create({}, 'DeviceCoverage'); me.deviceCoverage.getForm().loadRecord(me.deviceCoverageRecord); me.wizard = Ext.create('CsgPrepaid.views.Wizard', { items: me.deviceCoverage }); app.viewport.add(me.wizard); var nextButton = me.nextButton = me.wizard.wizardButtons.nextButton; me.backButton = me.wizard.wizardButtons.backButton; nextButton.setDisabled(true); nextButton.on('click', me.nextHandler, me); me.backButton.on('click', me.backHandler, me); me.deviceCoverage.viewCoverageButton.on('click', me.viewCoverageHandler, me); } me.backButton.setDisabled(true); nextButton.setText('[View Products]'); },
-
10 Mar 2011 5:11 PM #28
There is definitely a bug going on here... See my post / fix here:http://www.sencha.com/forum/showthre...n-error-object
Last edited by wizkid; 10 Mar 2011 at 5:12 PM. Reason: Spelling error
-
6 May 2011 2:06 AM #29Ext JS Premium Member
- Join Date
- Nov 2010
- Location
- Dillenburg, Hessen, Germany
- Posts
- 33
- Vote Rating
- 0
hey,
we have the same problem and want the form to validate by a given model and it's validations.
now i wrote my own ux.form.ModelValidatedPanel and ux.form.ModelValidatedBasic class that do this for me.
see here: http://www.diloc.de/blog/2011/05/05/...model-binding/
the main aim of the form is to hold a model-record what can validate by the model validations and give the error back to the form. and all this by behaving hopefully nearly the same like a normal Ext.form.Panel (validitychange etc.)
haven't tested it in our whole application context but my simple form example tests worked really fine.
-
6 May 2011 5:49 AM #30
I did something similar but I like yours allot better! I will have to give it a try! Thanks!
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