4

I got a small question: ExtJS 4.1 uses a mixin called "Ext.form.Labelable" for all form fields to render labels. I would like to change the labelableRenderTpl, which is the rendering template, for all form fields to add an extra label to the right side. How can i override/exend a mixin? Is it even possible or do i have to override the labelableRenderTpl for all classes who uses the mixin?

Thx for your help and best regards! Manuel

mesx
  • 1,035
  • 2
  • 12
  • 26

1 Answers1

6

You can apply a override for Ext.form.Labelable here

Ext.override(`Ext.form.Labelable`, {
    labelableRenderTpl: 'Your Template'
});

This is untested but it should work cause a mixin is defined like any other class. What you need to know is that now all classes that are using this mixin will use the new template. In case of of lableable this list is short

  • Ext.form.FieldContainer
  • Ext.form.field.Base
  • Ext.form.field.HtmlEditor

If you don't want to change it for all you will need to create your own mixin for example by extending Ext.form.Labelable and override Ext.form.field.Base to apply it to all fields.

You may find some more information about overriding here. (Even if some of the SO community seems to not like this question for your case you may find some valuable information in there)

Update

As you already guessed the problem is that the mixin was already copied to the class the time the override get applied so this is all about timing and may be ending in a hard match. I would recommend you to inherit from the Ext.form.Labelable mixin and apply this new mixin to all classes you need by overriding the implementation with your new mixin.

Community
  • 1
  • 1
sra
  • 23,820
  • 7
  • 55
  • 89
  • Hi and thank you very much for your answer. Unfortunately it's not working to override the mixin class with `Ext.override`. It does not affect the `FieldContainer`, `Base` and `HtmlEditor`. I guess this is because the mixin was already applied to this classes when i override the mixin?? I guess the only workaround is to override the mixin methods directly in the classes?? – mesx Mar 07 '13 at 08:51
  • 1
    @mesx If have read the link that I posted you would know that you cannot override a mixin method when it is just mixed in. By now I tested it and I must admit that it seems to be impossible to override a mixin. Neither override nor prototype does the job. This is a really odd behavior... I will look back at it later and give you feedback. – sra Mar 07 '13 at 09:37