How to override a default config option on Ext.form.Action.Submit?
Is there a way to configure ExtJS (through an Ext.override?) so that submitEmptyText config option for Ext.form.Action.Submit is false by default instead of true?
I know it's possible to override methods on classes but i don't know about default config properties, one might think that since config options are mostly public properties that console logging Ext.form.Action.Submit.submitEmptyText would output false but it is undefined.
One way I succeeded is by creating an interceptor for the run method but that basically renders the submitEmptyText config option useless since it can't be set anymore through a config object passed to the constructor.
Ext.form.Action.Submit.proto开发者_运维技巧type.run = Ext.form.Action.Submit.prototype.run.createInterceptor(function() {
this.options.submitEmptyText = false;
});
[Edited a few times, but this works for me]
submitEmptyText is not actually a property of the Ext.form.Action.Submit prototype -- it is just checked in the run function as a property of the "this.options" object -- which itself is defined on the superclass, Ext.form.Action
If you want it to be globally false by default, then just set it on the options property of Ext.form.Action after it is constructed
Ext.form.Action.prototype.constructor = Ext.form.Action.prototype.constructor.createSequence(function() {
Ext.applyIf(this.options, {
submitEmptyText:false
});
});
It's tricky, because the Ext.form.Action sets this.options to an empty object in its constructor, so you have to get access to that options property after the constructor executes, which is why a createSequence works in this case.
If you want to override the Ext.form.Action.submit() for all instances then why not just use an Ext.override?
Ext.override(Ext.form.Action.submit, {
submitEmptyText: false
});
If you want the submitEmptyText from Ext.form.Action.submit to be false, just set it in the config when you create the Ext.form.Action.submit object.
var submit = Ext.form.Action.submit({
submitEmptyText: false
});
It is very bold to use override, however if you are able to manage that changes the right way is:
Ext.override ( Ext.form.Action.submit, { submitEmptyText: false });
it will let to reverse this settings to true if needed. I also suggest to read http://edspencer.net/2009/07/extoverride-monkey-patching-ext-js.html
Maybe:
Ext.form.Action.submit.prototype.submitEmptyText = false.
This helps me with:
Ext.Window.prototype.constrainHeader = true;
精彩评论