No announcement yet.

Forcing decimals to show if zero in form field

  • Filter
  • Time
  • Show
Clear All
new posts

  • Forcing decimals to show if zero in form field

    Hi Guys, I'm beginning to wonder if this possible without overriding numberfield with a bunch of code. That's all I see on web searches coming from Sencha.

    Simple use case, it is a price field in US dollars. So you want "1.30" to show like that, instead you get 1.3. You can use util.Format.number in a grid column renderer, that works fine. But it does not work with a form field, using util.Format in the setValue clause of form field.

    Is there something I'm not aware of?

  • #2
    Hi Terry,

    You can override the numberfield to show zero decimals. Here is an example fiddle that shows zero decimals.
    Last edited by robert.swanson; 03-04-2020, 06:09 PM.


    • #3
      Thanks Johnny, that's a much cleaner override than other people had on forums. Be nice if Sencha would just implement that showZeroDecimals natively. But that is beside the point, they have not yet. :D

      My only other question to use your solution is where exactly do you override the numberfield in a MVC app? The controller? The window that hold form panel? All the examples I see on this are like your fiddle, I've never learned exactly how you implement that?


      • #4
        Since I don't know the structure of your application it's hard for me to say however you just need to add the override once.

        Let's say you have a main controller defined:
        Screen Shot 2020-03-04 at 8.25.19 PM.png

        You could add the override above the definition of the controller:
        Screen Shot 2020-03-04 at 8.26.06 PM.png


        • #5
          Wow, works like a charm. Yes, I have main controller. Have not switched to MVVM (and ViewControllers) because I'm targeting only desktop computers, no alternate views to phones or other small form factors yet.

          I just want to make sure I understand the scope of how override works. If defined in controller versus the panel/window (with the form/numberfield), does it make any difference? Meaning, if defined in one window/panel, does only apply to that window or can other windows in app still use it? Where controller definition would make it apply on all number fields in entire app?

          Just trying to understand the best practice in using this technique. I always thought this override stuff was applied in extjs version itself, affected all apps and meant each new version the overrides had to be implemented again. Had no idea it was this simple.