DecimalDigits not working in RadNumericTextBox

4 posts, 0 answers
  1. alphonse joseph
    alphonse joseph avatar
    9 posts
    Member since:
    Aug 2009

    Posted 16 Feb 2010 Link to this post

    Hi,
      I am using RadNumericTextBox inside EditItemTemplate of a RadGrid.  I have given DecimalDigits property of RadNumericTextBox as "2".  But it accepts more than 2 decimal places depending on the MaxLength property.  How can I restrict the decimal places only to 2 digits?  Code I have used given below:

     <telerik:GridTemplateColumn  HeaderText="Debit" UniqueName="debit" DataType="System.Decimal" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Right" >
                            <ItemTemplate>
                            <asp:Label ID="lblDbAmt" Text= '<%# Eval("dbamt") %>' CssClass="labels"   runat="server"> </asp:Label>
                            </ItemTemplate>
               
                           <EditItemTemplate>
                                   <telerik:RadNumericTextBox ID="txtDbAmt" Text  = '<%# bind("dbamt") %>' MinValue="0" MaxValue="99999999" MaxLength="11" DataType="System.Decimal" Culture="en-GB"  AutoPostBack="false" ClientEvents-OnKeyPress="KeyPressed" EnabledStyle-HorizontalAlign="Right" runat="server">                   
                                               <NumberFormat AllowRounding="false" DecimalDigits="2" DecimalSeparator="." GroupSeparator="," GroupSizes="3" KeepNotRoundedValue="true"   />
                                   </telerik:RadNumericTextBox>   
                           </EditItemTemplate>

                        </telerik:GridTemplateColumn>   


    Alphonse

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2010 Link to this post

    Hi Alphonse,

    Try the following approach by checking number of decimal places in the "onkeyup" event, and then reset the text according to the requirement.

    aspx:
     
    <telerik:RadNumericTextBox ID="txtDbAmt" onkeyup="check(this);" Text='<%# bind("Number") %>' 
        MinValue="0" MaxValue="99999999" MaxLength="11" DataType="System.Decimal" Culture="en-GB" 
        AutoPostBack="false" ClientEvents-OnKeyPress="KeyPressed" EnabledStyle-HorizontalAlign="Right" 
        runat="server"
        <NumberFormat AllowRounding="false" DecimalDigits="2" DecimalSeparator="." GroupSeparator="," 
            GroupSizes="3" KeepNotRoundedValue="true" /> 
    </telerik:RadNumericTextBox> 

    javascript:
     
        function check(textbox) { 
            var val = textbox.value; 
            if (val.length - val.indexOf('.') > 3 && val.indexOf('.') > 0) { 
                textbox.value = val.substr(0, (val.length - 1)); 
            } 
        } 

    -Shinu.
  3. alphonse joseph
    alphonse joseph avatar
    9 posts
    Member since:
    Aug 2009

    Posted 16 Feb 2010 Link to this post

    Hi Shinu,
        Thanks for your quick reply.  It works under normal conditions.  But if the user keeps a particular key pressed for a while, it fails.  Is there any way to avoid this situation? 

    Alphonse
  4. Dimo
    Admin
    Dimo avatar
    8482 posts

    Posted 17 Feb 2010 Link to this post

    Hi Alphonse,

    Check this out:

    <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
        <ClientEvents OnKeyPress="checkDecimals" />
    </telerik:RadNumericTextBox>
     
    <script type="text/javascript">
     
    function checkDecimals(sender, args)
    {
        window.setTimeout(function(){
         
            var tbValue = sender.get_textBoxValue();
            var tbDecimalPosition = tbValue.indexOf(sender.get_numberFormat().DecimalSeparator);
            if (tbDecimalPosition != -1 && tbValue.length > tbDecimalPosition + 3)
            {
                sender._textBoxElement.value = tbValue.substr(0, tbDecimalPosition + 3);
            }
         
        }, 1);
    }
     
    </script>


    Sincerely yours,
    Dimo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top