Clear text of C1ComboBox with no items in the ItemsSource

Posted by: jared.fritsch on 12 February 2018, 2:09 am EST

    • Post Options:
    • Link

    Posted 12 February 2018, 2:09 am EST

    Xamarin.Forms

    C1 version: v2.5.20173.241

    Affected platforms: UWP, iOS

    Unaffected platforms: Android

    I have a simple, editable C1ComboBox.

    <input:C1ComboBox
        x:Name="TheComboBox"
        IsEditable="True"
        DropDownBehavior="ButtonTap" />
    

    In some scenarios, the ItemsSource may actually get set to nothing, either null or an empty collection. However, we still want users to be able to type in them. The issue comes when we try to programatically clear these C1ComboBoxes. The following works on Android, but not UWP or iOS.

    private void Button_OnClicked(object sender, EventArgs e)
    {
    	TheComboBox.Text = "";
    }
    

    On UWP, you can see the text property is properly set as the entered in text, and setting it to an empty string is reflected on the property. But, it doesn’t seem to affect what is visually displayed in the C1ComboBox. If fact, this is true if you set Text to anything, including null. It still displays the entered in text. However, as long as the ItemsSource is null, I did find that setting the SelectedIndex to anything > -1 (even though there are no items) does clear the text. I wouldn’t have been surprised if that caused an error.

    However, the SelectedIndex trick does not work on iOS. iOS seems to have a few issues here. The first time my button click handler fires, no matter what is entered into the C1ComboBox, the Text property is an empty string. If I set the Text property to some string other than an empty string it does change, both on the property an visually. But, if I type something else in and click the button, the Text property shows what I had set it to programatically before, not what I typed in. The string I typed in stays displayed. The only thing that seems to work is if I set the Text property to null. For some reason, when I set it to null, the Text property is always an empty string on subsequent button clicks and null clears it out.

    So my UWP workaround is to set the SelectedIndex to something > -1 and my iOS workaround is to set the Text to null (which does also work on Android). I would really just expect them to work like Android though.

  • Posted 13 February 2018, 10:08 pm EST

    Hi Jared,

    I couldn’t reproduce the behavior at my end end on both UWP and iOS and have attached gif images for your reference. I have verified this with the Input101 demo sample and have attached it along with. Can you please try it at your end as well? When are you setting the ItemsSource of ComboBox to null? I have set it in the Button click just before setting the Text to “”.

    C1Input101_ComboBox.zip

  • Posted 14 February 2018, 3:30 am EST

    Sorry, I should have been a little more clear. The problem comes with trying to clear the text when the ItemsSource is already null. So in your repro project, try these steps:

    1. Type something into the “Editable” ComboBox
    2. Click the button to clear the text
    3. Notice that the text is cleared out and there are no more items in the dropdown
    4. Type something into the “Editable” ComboBox again
    5. Click the button again
    6. Notice that the text is not clearing out
  • Posted 14 February 2018, 7:59 pm EST

    Thanks for the additional steps. I could replicate the behavior with these steps. I’ve logged this as a bug in our system (tracking Id - 309192) and will update you once it is fixed. Thanks for reporting this issue.

  • Posted 2 April 2018, 5:05 pm EST

    Hi,

    The bug is fixed in the latest build (2.5.20181.267) and is available on Nuget. Kindly update your application with this build.

    Thanks

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels