We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Enable Return key

Hi,

I'm struggling to get the return key on the SfNumericTextBox to work properly. I want to dismiss the keyboard when I press the Return key. Both in Xamarin.Forms (using an Effect) and in Xamarin.iOS "classic". This is a simple version of my code:

                             var box = new SFNumericTextBox()
            {
                Frame = new CGRect(20, 20, 200, 200),
                ParserMode = SFNumericTextBoxParsers.Double,
                FormatString = "c",
                NumericTextBoxDelegate = new SFNumericTextBoxDelegate(),
                EnablesReturnKeyAutomatically = true
            };

            // once I set this, the textbox stops formatting numbers:
            box.ShouldReturn = (textField) =>
            {
                textField.ResignFirstResponder();
                return true;
            };
  

If I setup the ShouldReturn delegate, in the last line, the default behavior of the SfNumericTextBox seems to break. Now when I tap the text box, the currency symbol and formatting don't disappear and I can start typing any value including letters and symbols. So clearly these delegates should not be overwritten?

What is the proper way of enabling the Return key? I noticed that in Forms, the renderer automatically adds a Done button to the keyboard. Is this a workaround?

5 Replies

VA Vanaja  Annasamy Syncfusion Team March 28, 2017 04:41 PM UTC

 Hi Roy,

Thank you for contacting Syncfusion support.

In Xamarin.Forms, by default the keyboard will be disappeared while pressing the return key in Numeric text box.

In Xamarin.IOS, we have achieved your requirement “KeyBoard disappear while return key is pressed” in sample level. Please download the sample for the same from below link.

Sample: https://www.syncfusion.com/downloads/support/forum/129642/ze/SFNumericTextBox.iOS-750937093 

Please let us know if you have concern on this.

Regards,

Vanaja R.A.
 



RC Roy Cornelissen March 28, 2017 06:04 PM UTC

Hello Vanaja,

Thanks for your reply. Unfortunately your sample code project contains only empty classes. Perhaps something went wrong while zipping it?

We don't see the behaviour you mentioned in Forms, if we press the Return key, nothing happens in our Forms project. Any idea what could be causing this? This is how our Xaml looks for all our numeric text boxes:

<num:SfNumericTextBox Style="{DynamicResource NumericTextBox}" IsEnabled="{Binding FinancialAmountFieldInfo.Enabled}" FormatString="c" Culture="{Binding CurrentCulture}" Value="{Binding FinancialAmountValue}" AllowNull="true" MaximumNumberDecimalDigits="2" ParserMode="Double" />
                                    
 
The style referenced is as follows:

    <Style TargetType="num:SfNumericTextBox" x:Key="NumericTextBox">
        <Setter Property="FontSize" Value="16" />
        <Setter Property="VerticalOptions" Value="FillAndExpand" />
        <Setter Property="HorizontalOptions" Value="FillAndExpand" />
        <Setter Property="Margin" Value="0,0,16,0" />
        <Setter Property="BackgroundColor" Value="White" />
        <Setter Property="Watermark" Value="" />
        <Style.Triggers>
            <Trigger TargetType="num:SfNumericTextBox" Property="IsEnabled" Value="True">
                <Setter Property="TextColor" Value="{DynamicResource DefaultEditableTextColor}" />
            </Trigger>
            <Trigger TargetType="num:SfNumericTextBox" Property="IsEnabled" Value="False">
                <Setter Property="TextColor" Value="{DynamicResource DefaultLabelColor}" />
            </Trigger>
        </Style.Triggers>
    </Style>


VA Vanaja  Annasamy Syncfusion Team March 29, 2017 04:51 PM UTC

Hi Roy,

Sorry for your inconvenience.

Query: Return key support in SfNumericTextBox.

Since SfNumericTextBox is derived from Entry in Xamarin.iOS it exhibits the default behavior of Entry, so we have to add the return key manually. As per your requirement we have created a sample which provide return key (Done) support. Please download the same from below link.

Link: https://www.syncfusion.com/downloads/support/forum/129642/ze/NumericTextBoxiOS1008031520 

Please let us know if you have concern on this.

Regards,
Vanaja R.A. 



MB Matthew Belk June 18, 2019 03:49 PM UTC

With the SyncFusion 17.1.x release, the notion of making a custom renderer for the SfNumericTextBox no longer works on iOS. The renderer is never actually called, which tells me that something happened to the base class of the SfNumericTextBox in the latest versions. I should mention that I also upgraded to Xamarin.Forms 4.x

Here is my custom renderer code


using System;
using CoreGraphics;
using goRoamPOD.iOS.Renderers;
using Syncfusion.SfNumericTextBox.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(SfNumericTextBox), typeof(SfNumericTextBoxRenderer))]
namespace goRoamPOD.iOS.Renderers
{
    public class SfNumericTextBoxRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var toolbar = new UIToolbar(new CGRect(0.0f, 0.0f, Control.Frame.Size.Width, 44.0f))
                {
                    Items = new[]
                    {
                         new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                         new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { Control.ResignFirstResponder(); })
                     }
                };

                this.Control.InputAccessoryView = toolbar;
            }
        }
    }
}


RA Rachel A Syncfusion Team June 19, 2019 01:04 PM UTC

Hi Roy, 
 
Thanks for your interest in Syncfusion products. 
 
If you want to view return key in numeric up down, we have provided built-in support in both Xamarin iOS and Xamarin Forms which is available in 17.x version. So there is no need for using the custom renderer, you can upgrade to latest version. 
 
Please revert us if you have any other query. 
 
Regards, 
Rachel. 


Loader.
Live Chat Icon For mobile
Up arrow icon