Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:54:38+00:00 2026-06-17T06:54:38+00:00

I have an Ext.form.field.Text and I want to override the setValue function. What is

  • 0

I have an Ext.form.field.Text and I want to override the setValue function.

What is the recommended way to override this class functionality in ExtJS? Ext.override?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:54:39+00:00Added an answer on June 17, 2026 at 6:54 am

    For clarification:
    By real class modification I mean a intended permanent
    modification/extension of a class
    , which should always be done by extending a class.
    But it is not a temporary solution for just a specific problem (bug-fix, etc.).

    You have at least four options how to override members of (Ext) Classes

    • prototype I guess is well known and allows you to override a member for all instances of a class. You can use it like

      Ext.view.View.prototype.emptyText = "";
      

      While you can’t use it like

      // callParent is NOT allowed for prototype
      Ext.form.field.Text.prototype.setValue = function(val) {
          var me = this,
              inputEl = me.inputEl;
      
          if (inputEl && me.emptyText && !Ext.isEmpty(value)) {
              inputEl.removeCls(me.emptyCls);
              me.valueContainsPlaceholder = false;
          }
      
          me.callParent(arguments);
      
          me.applyEmptyText();
          return me;
      };
      

      Here’s a JSFiddle

      This variant should not be used for real class modifications.

    • Ext.override does nearly the same then prototype but it fully applies to the ExtJS Class-system which allows you to use callParent()

      You can use it like

      // callParent is allowed for override
      Ext.override('Ext.form.field.Text', {
          setValue: function(val) {
              this.callParent(['In override']);
              return this;
          }
      });
      

      Here’s a JSFiddle (c-p error fixed! Thanks to @nogridbag)

      Use case: I faced a (I think still existing) bad behavior of a
      radiogroup where ExtJS expect a object (key-value-pair) for correct
      setting of the value. But I have just one integer on my backend. I
      first applied a fix using Ext.override for the setValue()
      method and afterwards extend from radiogroup. There I just make a
      Key-Value-Pair from the given value and call the parent method with
      that.

      As @rixo mentioned this can be used for overriding a instance member. And may therefore be qualified for overriding even mixins (I never tested it myself)

      var panel = new Ext.Panel({ ... });
      Ext.override(panel, {
          initComponent: function () {
              // extra processing...
      
              this.callParent();
          }
      });
      

      This variant should not be used for real class modifications.

    • Extending a existent class to apply additional behavior & rendering. Use this variant to create a subtype that behaves different without loosing the original type.

      In the following example we extend the textfield with a method to change the labelcolor when setting a new value called setColored and override the setValue method to take care of removing a label color when setValue is called directly

      Ext.define('Ext.ux.field.Text',{
          extend: 'Ext.form.field.Text',
          widget: 'uxtextfield',
          setColored: function(val,color) {
              var me = this;
              if (me.settedCls) {
                  me.removeCls(me.settedCls);
              }
              me.addCls(color);
              me.settedCls = color;
              me.setValue(val,true);
          },
          setValue: function(val,take) {
              var me = this;
              if (!take && me.settedCls) {
                  me.removeCls(me.settedCls);
              }
              me.callParent(arguments);
              return me;
          }
      });
      

      Here’s a JSFiddle

    • Overriding per instance will happen in really rare cases and might not be applicable to all properties. In such a case (where I don’t have a example at hand) you have a single need for a different behavior and you might consider overriding a setting just per instance. Basically you do such things all times when you apply a config on class creation but most time you just override default values of config properties but you are also able to override properties that references functions. This completely override the implementation and you might allows don’t have access to the basetype (if any exist) meaning you cannot use callParent. You might try it with setValue to see that it cannot be applied to a existing chain. But again, you might face some rare cases where this is useful, even when it is just while development and get reimplemented for productive. For such a case you should apply the override after you created the specific by using Ext.override as mentioned above.

      Important: You don’t have access to the class-instance by calling this if you don’t use Ext.override!

    If I missed something or something is (no longer) correct, please comment or feel free to edit.

    As commented by @Eric

    None of these methods allow you to override mixins (such as Ext.form.field.Field). Since mixin functions are copied into classes at the time you define the class, you have to apply your overrides to the target classes directly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an form with a text area field. I want to add some
I have a form field and i want to read the text entered into
I'm using Ext.Form.Panel successfully but I want to use Ext.form.field.File this time. I was
I've been puzzling over the tabIndex config for ExtJS's Ext.form.field.Base (generic field, in other
I'm stumped on this. We have an ExtJS form where birthdate is entered. However,
I just create my component, based in 'Ext.form.field.Trigger' with this config params: config: {
I have a form panel and i want text fields stick to their labels
ExtJS 4.1. Let's imagine we have some form: Ext.define('App.view.editform', { extend: 'Ext.form.Basic', defaultType: 'textfield',
I am using this article of architecture http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/ in my code: I have this
I'm getting started with ExtJs. I'm building a very simple login form: Ext.onReady(function ()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.