Search code examples
xamarinautocompletesyncfusion

How to disable Syncfusion's Autocomplete from moving to the next entry when completed?


I'm using Syncfusion's Autocomplete entry in Xamarin.Forms in a way not related to a form. Thus, I don't want it to step to the next Entry object in the UI. However, doesn't matter what I try doing, when finishing putting in the input, it jumps to the next Entry.

I have tried setting both Entrys IsTabStop to False, as well as setting the second one's TabIndex to be smaller the other one's. Nothing worked, the only think which I have found to work is disabling the second Entry while the other one is focused.

XAML:

<ScrollView ...>
    // ....

    <StackLayout>
        // ....
        <autocomp:SfAutoComplete x:Name="TagsAutoComplete"
                                 WidthRequest="100"
                                 NoResultsFoundText="New Tag..."
                                 DisplayMemberPath="Name"
                                 Keyboard="Chat"
                                 IsTabStop="False"
                                 IsVisible="False"
                                 Completed="AddTagAutoComplete_Completed" />
        // ....
    </StackLayout>

    // ....

    <Frame>
        <Grid>
            // ....
            <Entry FontSize="18" TextColor="Black" 
                   WidthRequest="150" VerticalOptions="Center"
                   Unfocused="EquValueEntry_Unfocused" 
                   TabIndex="-1" IsTabStop="False" />
            // ....
        </Grid>
    </Frame>

    // ....
</ScrollView>

My workaround uses the Focused and Unfocused methods of the Autocomplete, which simply set the IsEnabled property of the second Entry to False and True respectively. Does anyone have a better, more elegant solution?


Solution

  • We would like to let know that you can stop the next Entry focus by Return type and IME option.

    UWP:

    Setting IsTabStop as false it disables the next Entry focus.

    Android:

    By changing the input method options of EditText in autocomplete (using ImeOptions property)

    protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) 
        { 
            base.OnElementChanged(e); 
            if (Control != null) 
            { 
                Control.GetAutoEditText().ImeOptions = Android.Views.InputMethods.ImeAction.Done; 
                Control.GetAutoEditText().SetImeActionLabel("Send", Android.Views.InputMethods.ImeAction.Done); 
            } 
    

    iOS:

    By changing the return type property of UITextField in autocomplete (using ReturnKeyType property)

    protected override void OnElementChanged(ElementChangedEventArgs<SfAutoComplete> e) 
        { 
            base.OnElementChanged(e); 
            if (Control != null) 
            { 
                Control.TextField.ReturnKeyType = UIReturnKeyType.Done; 
            } 
        } 
    

    We have prepared a sample for your reference get it from below link.

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

    For more information refer the link: https://www.syncfusion.com/kb/10690/how-to-change-return-button-type-in-sfautocomplete