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![]()
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 @LikelyMitch
Modus Create, Senior Frontend Engineer
________________
Need any sort of Ext JS help? Modus Create is here to help!
Check out my GitHub:
https://github.com/mitchellsimoens
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;
}
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 @LikelyMitch
Modus Create, Senior Frontend Engineer
________________
Need any sort of Ext JS help? Modus Create is here to help!
Check out my GitHub:
https://github.com/mitchellsimoens
I noticed that Ext JS 4 uses var me = this; What is the reason behind doing this?
- 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 @LikelyMitch
Modus Create, Senior Frontend Engineer
________________
Need any sort of Ext JS help? Modus Create is here to help!
Check out my GitHub:
https://github.com/mitchellsimoens
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?
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]'); },
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
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.
I did something similar but I like yours allot better! I will have to give it a try! Thanks!