Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > NumericTextBox > CurrencyTextBox: Help with custom value formatting
Telerik MVC Extensions are no longer supported (see this page for reference). In case you have inquiries about Kendo UI Complete for ASP.NET MVC, post them in the pertinent Kendo UI forums.

Not answered CurrencyTextBox: Help with custom value formatting

Feed from this thread
  • Posted on Dec 29, 2011 (permalink)

    I am trying to achieve some custom value formatting with the CurrencyTextBox, but the way that the control handles values is making things decidedly hard.

    What I want to do is this: if the user enters a value that does not contain a "." character, it will format that value as cents instead of dollars.  So if a user enters "16", I want the control to display (and contain a value of) $0.16.  If the user enters a value with a ".", I would like the control to function as normal.  If the user enters "16.", "16.0" or "16.00", I want the control to display (and contain a value of) "$16.00".  This application will be used by people in the retail business and this is how they expect inputs for price values to function.

    However, whether I subscribe to the OnChange event or even the "blur" event on the textbox itself, it is stripping the "." character if there is either nothing after it or only 0's after it.  Example: If I enter in a value of "16.", "16.0" or "16.00", the value pulled from the textbox in javascript will be "16".  And since I have to check for the presence of the "." character, this breaks my logic to properly format the value.

    So I'm looking for some help or suggestions.  Here is the javascript that I have right now to properly format the value as required.  As you can see, if the value does not contain a "." character, the value is divided by 100, which is exactly what I want.  Stripping this character is killing my logic.  :)

    $('custom-price').find('input').live('blur', function (e) {
        var sender = $(this).data('tTextBox');
        var priceVal = $(this).val(); // $(this).attr('value') also returns the value with the character stripped, FYI
        if (priceVal.indexOf(".") == -1) {
            priceVal = priceVal / 100;
        }
        sender.value(priceVal);
    });

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > NumericTextBox > CurrencyTextBox: Help with custom value formatting
Related resources for "CurrencyTextBox: Help with custom value formatting"

ASP.NET MVC NumericTextBox Features  |  Documentation  |  Demos  |  Telerik TV ]