Pre-select Content in DisplayPromptAsync to allow overwriting easily

Viewed 181

Currently in my Xamarin Forms app I am using a DisplayPrompt (https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.page.displaypromptasync?view=xamarin-forms) to ask the user the Quantity they want for a specific Product / Item using the code below:

var quantity = await Shell.Current.DisplayPromptAsync("Quantity",
    "How many?",
    initialValue: "1",
    maxLength: 2,
    keyboard: Keyboard.Numeric,
    accept: "OK",
    cancel: "Cancel");

I was wondering if there was any way to pre-select the initialValue inside of the Prompt so that the user can just press a value on the Keyboard to overwrite it, similar to if you was to call: SelectAll method in C# (https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.textboxbase.selectall?view=windowsdesktop-5.0)

I have done some research to see if I could create a Custom Control and this guide seems to be the closest possible solution https://theconfuzedsourcecode.wordpress.com/2017/07/26/an-await-able-transparent-custom-popup-input-dialog-in-xamarin-forms/, but I didn't want to add extra complexity or change the UI/UX for the dialogs just for this seemingly small bit of functionality.

The only other solution I could think of is to set the placeHolder value to be 1 and remove the initialValue and then just check that the returned value is empty and not null which means the user clicked OK so they are meaning to set it as 1 but I think this may be confusing to some of our Users who are not very "tech savvy".

Any suggestions would be greatly appreciated!

0 Answers
Related