xamarin forms autocomplete capitalization

Hello Syncfusion Support,
When using the SfAutoComplete component, how can we capitalize the word if it is not found in the list?
If the word is found, then we simply use it as is and if we want it capitalized, we put it in the list with a capital.
In our case we have a list of rooms like "Kitchen; Living Room; Bedroom". Now if they want to select "Hall" they type "hall" which by default is not capitalized. How can we get it automatically capitalized when they start typing?
Thanks

7 Replies 1 reply marked as answer

SS Suganya Sethuraman Syncfusion Team March 23, 2021 10:38 AM UTC

Hi Will,

Greetings from Syncfusion.

We have analyzed your query. We have achieved your requirement using CustomRenderer as below code snippet,

Code Snippet
 
public class CustomAutoCompleteRenderer : Syncfusion.SfAutoComplete.XForms.Droid.SfAutoCompleteRenderer 
    { 
        public CustomAutoCompleteRenderer(Context context) : base(context) 
        { 
        } 
 
        protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) 
        { 
            base.OnElementChanged(e); 
            if (Control != null) 
            { 
                Control.GetAutoEditText().InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextFlagCapWords; 
            } 
        } 
    } 

Please have the sample
for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoComplete_Captial2104512714

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Marked as answer

WA Will Autio March 23, 2021 11:00 PM UTC

Hi Suganya Sethuraman,

Thanks for the reply and especially the sample. It works fine for me. 


I tried to do something similar to what you sent me for UWP, but alas, I was not successful.

What would the Renderer look like in UWP?


Thanks!

Best Regards,

Will



SS Suganya Sethuraman Syncfusion Team March 24, 2021 06:19 AM UTC

Hi Will,

Thanks for the update.

We have analyzed your requirement. we added a custom renderer to the UWP project to capitalize the first letter of the entered text as code snippet below,

Code snippet
 
    public class CustomAutocompleteRenderer : SfAutoCompleteRenderer 
    { 
        protected override void OnElementChanged(ElementChangedEventArgs<Syncfusion.SfAutoComplete.XForms.SfAutoComplete> e) 
        { 
            base.OnElementChanged(e); 
            if (Control != null) 
            { 
                Control.TextChanged += Control_TextChanged; 
            } 
        } 
 
        private void Control_TextChanged(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e) 
        { 
            SfTextBoxExt textBox = (SfTextBoxExt)sender; 
 
            CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; 
            TextInfo textInfo = cultureInfo.TextInfo; 
            textBox.Text = textInfo.ToTitleCase(textBox.Text.ToLower()); 
            textBox.Select(textBox.Text.Length, 0); 
        } 
    } 

Please have the sample for your reference,


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoCompleteUWPRenderer-1902824520

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 



WA Will Autio March 24, 2021 05:14 PM UTC

Awesome - works like a charm!
Thanks,
Will


SS Suganya Sethuraman Syncfusion Team March 25, 2021 10:09 AM UTC

Hi Will,

Thanks for the update.

We are glad to know that the given solution works. Please let us know if you need any further assistance.

Regards,
Suganya Sethuraman.
 



WA Will Autio April 15, 2021 10:17 PM UTC

Hi Suganya Sethuraman,

Please add one refinement to this code. I had a case where I opened a page that used AutoComplete and then I immediately closed it again, without doing anything. Specifically, without using the AutoComplete component, I would end up in this code and the Control is null. That caused a nasty crash. But only in iOS because iOS did not check for Control != null. So, I had to amend the code to look like this:
```
        protected override void OnElementChanged(ElementChangedEventArgs<Syncfusion.SfAutoComplete.XForms.SfAutoComplete> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.TextField.AutocapitalizationType = UITextAutocapitalizationType.Words;
            }
        }
```

Please amend your samples to include the check for a null Control.
I noticed that the Android and UWP versions of the OnElementChanged check for null.

Thanks for all your help!

Regards,
Will Autio


SS Suganya Sethuraman Syncfusion Team April 16, 2021 07:44 AM UTC

Hi Will,

Thanks for the update.

We have considered your suggestion. Please let us know if you need any further assistance.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon