Xfx.Controls icon indicating copy to clipboard operation
Xfx.Controls copied to clipboard

How to turn off Autocorrection, spell checker, AutoCapitaliztion for XfxEntry control

Open quantumarun opened this issue 6 years ago • 12 comments

I need to turn off autocorrection when typing some text. Right now if i something say serah then on iOS it will automatically by corrected to search. Is there a build in property already for this?

Bug

  • Version Number of Control:
  • Device Tested On:
  • Simulator Tested On:

Affects

  • [x] iOS
  • [ ] Android

Expected Behavior

Actual Behavior

Steps to reproduce the Behavior

Link to Github Reproduction (optional but recommended)

Repro

Feature Request:

Please fill in what you would like

quantumarun avatar Apr 01 '18 13:04 quantumarun

Try setting the Keyboard to 'Text'

ChaseFlorell avatar Apr 01 '18 13:04 ChaseFlorell

Already tried this but still autocorrection happens

quantumarun avatar Apr 01 '18 13:04 quantumarun

Does it happen if you use a regular Entry control?

ChaseFlorell avatar Apr 01 '18 14:04 ChaseFlorell

Yes. Same thing happens there also. Also i have writing a custom renderer on XfxEntry controls for ios and set the autocorrection to none but still the autocorrection happens.

quantumarun avatar Apr 03 '18 18:04 quantumarun

You didn't specify if you're on a device or simulator. Do you happen to have a custom keyboard by chance?

ChaseFlorell avatar Apr 03 '18 19:04 ChaseFlorell

Its having on both device and simulator. No i don't have custom keyboard. Attached is the snapshot for your reference. As in the screenshot, i want to disable the suggestion coming just over the keyboard.

simulator screen shot - iphone x - 2018-04-04 at 21 19 21

quantumarun avatar Apr 04 '18 17:04 quantumarun

Hello, I also reproduce this issue on both IPhoneSimulator and real IPhone. Can you fix this thing?

This issue is very important for login form.

I would do this in the simple entry (and it works):

<Entry Placeholder="test" Keyboard="Text"> <Entry.Keyboard> <Keyboard x:FactoryMethod="Create"> <x:Arguments> <KeyboardFlags>None</KeyboardFlags> </x:Arguments> </Keyboard> </Entry.Keyboard> </Entry>

boskokg avatar Jun 13 '18 23:06 boskokg

I've never contributed to a project before on github, and I'm not that good at XF to be able to build my own control but I have a control called NoHelperEntry (which I used online tutorials for). Its fairly straightforward but I wonder if instead of inheriting from Entry you inherit from NoHelperEntry instead?

so in the shared project:

namespace Controls { public class NoHelperEntry : Entry { } }

then in the iOS and Android projects you have these renders:

Android

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Text;
using Project.Controls;
using Project.Droid.Renderers;
using View = Android.Views.View;

[assembly: ExportRenderer(typeof(NoHelperEntry), typeof(NoHelperEntryRenderer))]
namespace Project.Droid.Renderers
{
public class NoHelperEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            Control.ShowSoftInputOnFocus = false;
        }

        private void Control_FocusChange(object sender, FocusChangeEventArgs e)
        {
            if (e.HasFocus)
            {
				Control.ShowSoftInputOnFocus = false;
            }
            else
            {
				Control.ShowSoftInputOnFocus = false;
				
            }
        }
    }
}

iOS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using UIKit;
using CoreGraphics;
using Project.iOS;
using Project;
using Foundation;
using UIKit;
using Project.Controls;

[assembly: ExportRenderer(typeof(NoHelperEntry), typeof(NoHelperEntryRenderer))]
namespace Project.iOS
{
    public class NoHelperEntryRenderer : EntryRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.InputView = new UIView();

                Control.SpellCheckingType = UITextSpellCheckingType.No;             // No Spellchecking
                Control.AutocorrectionType = UITextAutocorrectionType.No;           // No Autocorrection
                Control.AutocapitalizationType = UITextAutocapitalizationType.None; // No Autocapitalization
            }
        }
    }
}

So with a big proviso that I may be doing it completely wrong, hopefully this helps!

ChrisAllisonMalta avatar Aug 02 '18 19:08 ChrisAllisonMalta

Same problem, any idea how fix this? @ChaseFlorell

juanagu avatar Aug 08 '18 12:08 juanagu

I can't change the Keyboard for this custom entry control through XAML, code-behind or MVVM binding. From source code on the iOS Entry renderer, it looks like the Keyboard is being manually set to Native. It seems like this is the reason the Keyboard property is never getting applied to the entry, it's being overwritten by SetKeyboard(). I can do some experimenting with this when I get the time

Daxton47 avatar Jan 22 '19 18:01 Daxton47

I can't change the Keyboard for this custom entry control through XAML, code-behind or MVVM binding. From source code on the iOS Entry renderer, it looks like the Keyboard is being manually set to Native. It seems like this is the reason the Keyboard property is never getting applied to the entry, it's being overwritten by SetKeyboard(). I can do some experimenting with this when I get the time

I'm having a similar issue when trying to set the Keyboard flag to CapitalizeCharacter (or any other value). I tried doing it in XAML and in .cs, It just gets ignored in iOS. In Android, it works as expected.

Did you (or anyone) find a workaround?

jokogarcia avatar Jan 14 '20 12:01 jokogarcia

Yes, it is indeed setting the KeyboardType using .ToNative() that is at the root of the issue. You can illustrate this by replacing the SetKeyboard() with the following, which no longer auto-capitalizes:

private void SetKeyboard()
{
     Control.ApplyKeyboard(Keyboard.Create(KeyboardFlags.CapitalizeNone));
     Control.ShouldReturn = InvokeCompleted;
}

Of course, this obviously doesn't solve the issue since it would then ignore your Keyboard property altogether :) The solution seems to be to update the SetKeyboard to use ApplyKeyboard() and only use ToNative() for the numberpad comparison:

private void SetKeyboard()
{
    var kbd = Element.Keyboard;
    Control.ApplyKeyboard(kbd);
    Control.InputAccessoryView = kbd.ToNative() == UIKeyboardType.NumberPad ? NumberpadAccessoryView() : null;
    Control.ShouldReturn = InvokeCompleted;
}

With this change I am then able to easily set the keyboard type and flags via XAML:

<xfx:XfxComboBox
    Placeholder="Enter text"
    SelectedItem="{Binding SelectedItem}"
    ItemsSource="{Binding TextSuggestions}">
    <xfx:XfxComboBox.Keyboard>
        <Keyboard x:FactoryMethod="Create">
            <x:Arguments>
                <KeyboardFlags>CapitalizeNone</KeyboardFlags>
            </x:Arguments>
        </Keyboard>
    </xfx:XfxComboBox.Keyboard>
</xfx:XfxComboBox>

While still maintaining the ability to specify a default keyboard type:

<xfx:XfxComboBox 
    Placeholder="Enter email"
    SelectedItem="{Binding SelectedItem}"
    Text="{Binding EmailAddress}"
    ItemsSource="{Binding EmailSuggestions}"
    Keyboard="Email" />

I'll try to put together a pull request (hoping that it'll get applied), but I thought I'd at least post this here for others since I had the same issue and there hasn't been any update.

kiddailey avatar Jun 03 '20 23:06 kiddailey