Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug][DatePicker][XF5] DatePicker empty format now invalid #13577

Closed
McFlemchSoda opened this issue Jan 28, 2021 · 6 comments · Fixed by #14695
Closed

[Bug][DatePicker][XF5] DatePicker empty format now invalid #13577

McFlemchSoda opened this issue Jan 28, 2021 · 6 comments · Fixed by #14695

Comments

@McFlemchSoda
Copy link

McFlemchSoda commented Jan 28, 2021

Since I updated to Xamarin.Forms 5.0 the DatePicker does not accept Format = " " anymore. I use this to simulate a nullable datepicker. When the binded date is null it just defaults to the current date in a M/dd/yy format and does not work with an empty format anymore. Since Xamarin does not yet support a nullable datepicker, we do rely on the manipulation of Format in a custom renderer to re-create this effect.

I'd like to know if this can be fixed/reverted or if we shift focus to finish the Nullable DatePicker that's been waiting to be finished. #10175

Reproduction steps

  1. Open attached solution, it is still using Xamarin Forms 4.8.0.1821
  2. Run app to see that the datepicker label is empty
  3. Pick a date to see it changes, after press the button "Wissen" which should delete the date again (Wissen means Delete in Dutch)
  4. Either upgrade this solution to Xamarin Forms 5, or open the other solution which is already XF5, it has the same code, just upgraded.
  5. Run app again to see the datepicker has a default value and the button "Wissen" (Delete) does not work anymore.

Expected Behavior

When format = " " we expect the date label to be empty as in previous versions.
See section screen recordings for examples.

Actual Behavior

Changing format = " " gets ignored and defaults to M/dd/yy of even crashes because the DateFormat is not recognised.

Basic Information

  • Version with issue: Xamarin.Forms 5.0.0.1931
  • Last known good version: Xamarin.Forms 4.8
  • Platform Target Frameworks:
    • iOS: iPhone 12 pro iOS 14.3 Simulator & iPhone 7 iOS 14.3
    • Android: Samsung S8 device with Android 8
  • Android Support Library / AndroidX Version:
  • NuGet Packages: Xamarin.Forms 5.0.0.1931
  • Affected Devices: Samsung S8 Android 8, iPhone 7 iOS 14.3

Environment

Visual Studio Enterprise 2019 for Mac

Sample solutions

DatePicker_XF4.8.0.1821.zip
DatePicker_XF5.0.0.1931.zip

Screen Recordings

"Wissen" means Delete in Dutch. When clicking that button the date needs to disappear because we set Format = " ". Which happens in XF4.8 but goes to default in XF5.

XF 4.8 Nullable DatePicker
https://user-images.githubusercontent.com/8875682/106153509-eaeb6100-617e-11eb-9891-392d4ffcf35d.mov

XF5 DatePicker
https://user-images.githubusercontent.com/8875682/106153748-2ab24880-617f-11eb-9fe3-49b4c9f24e43.mov

Workaround

Since setting the DatePicker Format is not working properly I manipulate Control.Text. in my custom renderer in the OnElementChanged I check if the date from my custom NullableDatePicker is null and then set Control.Text = string.Empty

NullableDatePicker baseDatePicker = this.Element as NullableDatePicker;
if (baseDatePicker.NullableDate == null)
{
     Control.Text = string.Empty;
}

EDIT: Added a sample solution with our custom renderer + Reproduction steps
EDIT2: Found a workaround for my specific case.

@McFlemchSoda McFlemchSoda added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 28, 2021
@samhouts samhouts added this to New in Triage Jan 28, 2021
@rachelkang
Copy link
Contributor

Hi, @McFlemchSoda - thanks for submitting this issue! I'm having some trouble reproducing this - how were you setting the format in 4.8? Are you doing <DatePicker Format=" " /> or is your code more involved? This crashes for me on 4.8 as well - which version of XF 4.8 was it working for you on?

@rachelkang rachelkang added a/datepicker s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Feb 4, 2021
@rachelkang rachelkang moved this from New to Needs Info in Triage Feb 4, 2021
@McFlemchSoda
Copy link
Author

McFlemchSoda commented Feb 5, 2021

Hi @rachelkang!
I've updated the issue with two sample projects and reproduction steps. It uses a stripped down custom renderer our actual project uses. It works with 4.8.0.1821 and stops working once I go up to 5.x.
Let me know if there's more that I can do, or if you maybe found a workaround that I could use for now.

@McFlemchSoda
Copy link
Author

McFlemchSoda commented Feb 5, 2021

So, I've done some more testing and at least found a way to make my delete button work again. For some reason I did Control.Text = string.Empty for the Android renderer but not for iOS. This at least makes it look like the date has been reset.

But there still is an issue with setting the format. When loading the page the first time I tried setting Format = "pick a date..." instead of our normal Format = " ", because the date should be empty when loading the screen. But what I get in the datepicker is "pick a 4aae...". So it's trying to format it to a string but something is still pushing through with the date, because the 4 represents the date I chose before which was 02/04/2021. For example if I chose 02/05/2021 and then "deleted" the value and setting the Format = "pick a date..." then the picker would show "pick a 5aae...". Notice how the 4 now became a 5. So it's trying to push the date into the formatted string? I've tried this with multiple dates and different texts and it keeps showing a number in the formatted string related to the date.

@McFlemchSoda
Copy link
Author

Since setting the Format doesn't work properly anymore I did the following workaround for my specific case.
I added the following to OnElementChanged in my custom renderers to check if the date was null and then set the text instead of the format.

NullableDatePicker baseDatePicker = this.Element as NullableDatePicker;
if (baseDatePicker.NullableDate == null)
{
     Control.Text = string.Empty;
}

@McFlemchSoda
Copy link
Author

Any update on this?

@Redth Redth removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Mar 4, 2021
@PureWeen PureWeen moved this from Needs Info to Ready For Work in Triage Mar 5, 2021
@PureWeen PureWeen added this to To Fix in 5.0.0 SR 4 (Planning) via automation Mar 5, 2021
@PureWeen PureWeen added i/regression p/iOS 🍎 and removed s/unverified New report that has yet to be verified labels Mar 5, 2021
@Redth Redth moved this from Ready For Work to Needs Estimate in Triage Mar 22, 2021
@jfversluis
Copy link
Member

Hey @McFlemchSoda (Netherlands represent!), a PR for this is open now (#14695), would you be able to grab the NuGet as described here and let us know if this fixes this issue? That will greatly speed up the review process.

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

@jfversluis jfversluis removed this from To Fix in 5.0.0 SR 4 (Planning) Oct 5, 2021
@jfversluis jfversluis moved this from To Fix to PR Needs Review in 5.0.0 SR6 (Planning) - Target Date Oct. 13th Oct 5, 2021
Triage automation moved this from Needs Estimate to Closed Oct 11, 2021
5.0.0 SR6 (Planning) - Target Date Oct. 13th automation moved this from PR Needs Review to Done Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Triage
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants