开发者

remove plugins in ext javascript form via code?

开发者 https://www.devze.com 2022-12-24 17:54 出处:网络
i have the following form item { fieldLabel:\'Usernam开发者_如何学JAVAe\' ,id:\"username\" ,name:\'username\'

i have the following form item

{
 fieldLabel:'Usernam开发者_如何学JAVAe'
,id:"username"
,name:'username'
,allowBlank:false
,plugins:[Ext.ux.plugins.RemoteValidator]
,rvOptions: {
    url:'/registration/member/valid-username'
}

is it possible to remove plugins later via code?


I don't think so. init in the plugin runs when the component is initialized, so "later in the code" it's too late - "the damage has been done", and the plugin has hooked into the component's events, etc. It would be cool if I were wrong.


Well, it's functionally possible to support plugin deactivation (not sure about actually removing the plugin altogether), but most plugins probably don't do so unless they have some reason to support it. You should be able to write an override to the plugin and insert code that would allow you to activate/deactivate its functionality. Depends on the specific plugin of course, but if the plugin is well-written it should be overrideable.

My general approach would be something like:

Ext.override(Ext.ux.plugins.SomePlugin, {
   isActive: true,
   doSomething: function(){
      if(this.isActive){
          // copy orig doSomething
      }
   }
});

Then you could simply set pluginInstance.isActive = true/false as needed. Note that this is simplistic -- your plugin might take a lot more work to override effectively. But this approach would be a good place to start.

Or you could maybe get fancy and use createInterceptor functions on the plugin to do something similar without duplicating code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号