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

Disable Autocomplete feature in DataForm entry keyboard

Hi, 

I'd like to control whether the Autocomplete feature is available for the keyboard that appears when typing into a SFdataform generated text entry. Basically I'd like to optionally turn it off or if required globally set it to off. 

Is this something that can be done using built in Syncfusion capabilities at all? 

Thanks,
John

5 Replies

JD John Diamond July 23, 2018 04:54 AM UTC

Hello. 

I've found a solution to this problem. I'll list it here in case anyone else is interested. 

If you use the DataForm_AutoGeneratingDataFormItem method and look for the Entry control you want to remove the Autocomplete for then you can by setting the Keyboard property = Keyboard.Plain (Plain keyboard has the KeyboardFlags enum set to 'None'). 

e.g.

if (e.DataFormItem != null && e.DataFormItem.Name == "Firstname")
               (e.DataFormItem as DataFormTextItem).KeyBoard = Keyboard.Plain; 




VR Vigneshkumar Ramasamy Syncfusion Team July 23, 2018 06:42 AM UTC

Hi John,  
 
We are glad to know that your requirement has been achieved. Please get in touch if need further assistance on this.  
 
Regards 
Vigneshkumar R 



PA Patrick July 30, 2018 04:01 PM UTC

I am also facing the same issue as John. After trying to solution, John provided, the auto complete was still shown. I even tried a custom DataFormTextEditor, but still no luck (both on Android 8.0 simulator and actual Android 8.0 device)


DataForm.RegisterEditor("Text", new CustomTextEditor(DataForm));

public class CustomTextEditor : DataFormTextEditor
    {
        public CustomTextEditor(SfDataForm dataForm) : base(dataForm)
        {
        }

        protected override void OnInitializeView(DataFormItem dataFormItem, Entry view)
        {
            // Tried different options
            view.Keyboard = Keyboard.Create(KeyboardFlags.None);
            view.IsTextPredictionEnabled = false;

            base.OnInitializeView(dataFormItem, view);
        }
    }


VR Vigneshkumar Ramasamy Syncfusion Team August 7, 2018 04:32 AM UTC

Hi Patrik,  
   
Based on the provided information, we have analyzed with the mentioned query with disable auto complete in Xamarin Forms Android platform soft keyboard.  
   
Your requirement can be achieved through DataFormTextEditor as mentioned by you, but we have already logged issue for Custom Keyboard settings not working (None, Suggestions, Capitalization and so). We will include this issue fix in our upcoming Volume 2 SP2 release.  
   
Instead, you can achieve the same by using Custom text editor in SfDataForm.Please find the below link for more details.  
   
Code example.  
      dataForm.DataObject = new ContactInfo(); 
        dataForm.RegisterEditor("Entry", new CustomEntryEditor(dataForm));  
            dataForm.RegisterEditor("FirstName", "Entry"); 
  
   
   
In order to update the DataObject values when using custom editor, you should update the  DataForm Item editor value manually by using OnCommitValue override method of DataFormEditor class on TextChanged event which is used to commit the customized value in DataObject   
   
   
  
 
        public class CustomEntryEditor : DataFormEditor<CustomEntry> 
        { 
 
            public CustomEntryEditor(SfDataForm dataForm) : base(dataForm) 
            { 
 
            } 
 
            protected override CustomEntry OnCreateEditorView() 
            { 
                CustomEntry customEntry = new CustomEntry(); 
                customEntry.Keyboard = Keyboard.Create(KeyboardFlags.None); 
 
                return customEntry; 
            } 
 
            protected override void OnInitializeView(DataFormItem dataFormItem, CustomEntry view) 
            { 
                base.OnInitializeView(dataFormItem, view); 
            } 
            protected override void OnWireEvents(CustomEntry view) 
            { 
                view.TextChanged += View_TextChanged; 
                view.Unfocused += View_Unfocused; 
            } 
 
            protected override bool OnValidateValue(CustomEntry view) 
            { 
                var dataFormItemView = view.Parent as DataFormItemView; 
                return (DependencyService.Get<IDataForm>().ValidateDataFormItem(DataForm)); 
            } 
            private void View_Unfocused(object sender, FocusEventArgs e) 
            { 
                OnValidateValue(sender as CustomEntry); 
            } 
 
            private void View_TextChanged(object sender, TextChangedEventArgs e) 
            { 
                OnCommitValue(sender as CustomEntry); 
            } 
 
            protected override void OnCommitValue(CustomEntry view) 
            { 
                var dataFormItemView = view.Parent as DataFormItemView; 
                var textValue = view.Text; 
                this.DataForm.ItemManager.SetValue(dataFormItemView.DataFormItem, view.Text); 
            } 
        } 
  
   
In the nativeAndroid renderer, need to set the InputType to the Control as (Android.Text.InputTypes.TextFlagNoSuggestions | Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationVisiblePassword) SettingInputTypes.TextVariationVisiblePassword,  
Will be a work around to achieve your requirement. It turns off suggestion on soft keyboards.  
   
   
   
   
   
[assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomLabelRenderer))]  
namespace EntrySample.Droid 
    { 
        public class CustomLabelRenderer : EntryRenderer 
        { 
            public CustomLabelRenderer() 
            { 
            } 
 
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
            { 
                base.OnElementChanged(e); 
                if (e.NewElement != null) 
                { 
 
                    if (Control != null && !Control.IsSuggestionsEnabled) 
                        Control.InputType = Android.Text.InputTypes.TextFlagNoSuggestions | Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationVisiblePassword; 
                } 
            } 
        } 
    } 
  
   
Also you need to manually validate the data form item  by using OnValidateValue of DataFormEditor class in Unfocused event.    
   
Kindly find the sample for the same.  
   
Sample:  SfDataFormEntry
  
   
In the above sample we have manually did the validation in ValidateDataFormItem    
internal method of native renderer of DataForm ItemManager class by using Reflection.   
   
ssembly: Xamarin.Forms.Dependency(typeof(DataFormValidation))]   
   
    public class DataFormValidation : IDataForm 
    { 
        public bool ValidateDataFormItem(SfDataForm dataForm) 
        { 
            var nativeObject = dataForm.GetType().GetProperty("NativeObject", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(dataForm); 
 
            if (nativeObject != null) 
            { 
                var nativeDataForm = (nativeObject as Syncfusion.Android.DataForm.SfDataForm); 
                var method = nativeDataForm.ItemManager.GetType().GetMethod("ValidateDataFormItem", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); 
                var nativedataFormItem = nativeDataForm.ItemManager.DataFormItems["FirstName "]; 
                if (nativedataFormItem != null && method != null) 
                { 
                    var nativeValue = nativeDataForm.ItemManager.GetValue(nativedataFormItem); 
                    method.Invoke(nativeDataForm.ItemManager, new object[] { nativedataFormItem, nativeValue, true }); 
                    var isValid = nativedataFormItem.GetType().GetProperty("IsValid", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).GetValue(nativedataFormItem); 
                    return (bool)isValid; 
                } 
            } 
            return true; 
        } 
    } 
   
  
   
Screenshot:  
   
   
Note:  
However, setting Keyboard property and IsTextPredictionEnabled as False in the custom editor will be working fine in lower version (like Android 4.4 version).But we have facing the issue with Entry suggestion disable in higher version of Android.  
   
We have created a Xamarin Forum link for the same, kindly find the link below,  
   
Please let us know if this help full.  
 
Regards 
Vigneshkumar R 



JN Jayaleshwari N Syncfusion Team September 24, 2018 09:41 AM UTC

Hi Patrik, 
 
We are glad to announce that our Essential Studio 2018 Volume 3 Main Release v16.3.0.21 is rolled out and is available for download under the following link.          
The reported issue “The custom keyboard settings is not working in DataFormTextEditor.has been resolved and included in this release .We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.     
     
Regards,     
Jayaleshwari N.  


Loader.
Up arrow icon