Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override a default config option on Ext.form.Action.Submit?

Tags:

extjs

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.prototype.run = Ext.form.Action.Submit.prototype.run.createInterceptor(function() {
    this.options.submitEmptyText = false;
});
like image 323
ChrisR Avatar asked Feb 16 '11 08:02

ChrisR


3 Answers

[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.

like image 164
Johnathan Hebert Avatar answered Oct 24 '22 15:10

Johnathan Hebert


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
});
like image 34
JamesHalsall Avatar answered Oct 24 '22 17:10

JamesHalsall


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
});
like image 24
NT3RP Avatar answered Oct 24 '22 17:10

NT3RP