[CLOSED] Price Input Mask

  1. #1

    [CLOSED] Price Input Mask

    Hi,

    I want to define an input mask for ext:TextField to display prices with comma delimiter for receipts as follows:

    <ext:TextField ID="txtTotalAmount" ReadOnly="true" Text="0" LabelWidth="180" ClientIDMode="Static"  runat="server" Flex="1" FieldLabel="Total Amount" LabelAlign="Left" >
    	<Plugins>
    		<ext:InputMask runat="server" Mask="999,999,999,999,999" />
    	</Plugins>                                                                    
    </ext:TextField>
    It give me error "NaN" if I set the value to 35213.215 dollar.

    App.txtTotalAmount.setValue("35213.215");
    2. How to build a mask for the prices?

    Regards,
    Alaswad
    Last edited by fabricio.murta; Mar 02, 2016 at 12:27 PM.
  2. #2
    Hello, Alaswad!

    I'm not really sure how you need it. Can you show some valid input and output displayed you want in different situations?
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi,

    Here some examples:

    190000.000 --> 190,000.000
    25352.651 --> 25,352.651
    1234567.987 --> 1,234,567.987

    Regards,
    Alaswad
  4. #4
    You shouldn't be using input mask here, cause it is not flexible enough for your case.

    It seems this is a read-only field which is not having user input, right? So you'll be setting its value i.e. by a js function or database feed with the final value in the format you specified.

    That said, when you fill the value, you should use a number formatter. See if this example fits your scenario:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            var formatFieldNumber = function (item, newValue) {
                var formattedValue;
    
                if (newValue != null && typeof(newValue) == "string" && newValue.length > 0) {
                    // Strip the number from anything not an actual number
                    formattedValue = newValue.replace(/[^0-9.]/g, '');
    
                    // If the number has more than 4 digits, then start formatting it
                    if (formattedValue.length > 1) {
                        formattedValue = Ext.util.Format.number(formattedValue, '0,000.000');
                    }
    
                    // Update the field with the formatted number
                    if (formattedValue != newValue) {
                        item.setValue(formattedValue);
                        App.statusBar.setText("Provided value: " + newValue + " - Formatted value: " + formattedValue);
                    }
                }
            }
    
            var mkRandNum = function () {
                // From 1E-3 to 1E+10
                var integerDigits = Math.floor((Math.random() * 13) + 1) - 3;
    
                // Return string with the formatted random number
                return (Math.random() * Math.pow(10, integerDigits)).toString();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager runat="server" />
            <ext:TextField ID="txtTotalAmount" Text="0" LabelWidth="180" ClientIDMode="Static"  runat="server" Flex="1" FieldLabel="Total Amount" LabelAlign="Left" />
            <ext:Button runat="server" Text="Fill new value" OnClientClick="formatFieldNumber(App.txtTotalAmount, mkRandNum());" />
            <ext:Label runat="server" ID="statusBar" Text="Provided value: N/A - Formatted value: N/A" />
        </div>
        </form>
    </body>
    </html>
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thanks a lot.
    Correct.
    Works fine.

Similar Threads

  1. [CLOSED] Input mask
    By barnali in forum 3.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 14, 2015, 9:27 AM
  2. Input Mask in a text box
    By SeshuKumar in forum 2.x Help
    Replies: 0
    Last Post: Jun 09, 2014, 10:48 AM
  3. [CLOSED] Remove TextField's Input Mask
    By RCN in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 05, 2013, 4:19 PM
  4. Input mask by code behind
    By ermanni.info in forum 2.x Help
    Replies: 3
    Last Post: Jan 13, 2013, 2:40 PM
  5. [CLOSED] Input Mask for textfield
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 20, 2010, 10:20 AM

Posting Permissions