Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates #1862

Merged
merged 5 commits into from
Jun 17, 2021

Conversation

jtwotimes
Copy link
Contributor

I have a use case for the MudDatePicker where I would like to prevent users from selecting certain dates within the picker's calendar. Currently the only functionality to support anything like this are the MinDate and MaxDate component parameters, but these don't prevent the user from selecting any arbitrary dates/ranges (for example: prevent the user from selecting dates after the 5th of each month; or given a set of dates, only allow for date selection within this set).

Add the ability for users to set a Func<DateTime, bool> IsDateDisabled component parameter: if this returns true for a given calendar date, the calendar date button is disabled, preventing the user's selection. This also works for the MudDateRangePicker by only allowing for ranges to be picked if no date between the range's start and end dates return true for the provided function.

I was going to handle form validation for this feature as well, but I noticed there wasn't any validation logic for the MinDate and MaxDate either, so I wasn't sure of the best way to handle this.

@@ -35,6 +35,12 @@ protected async Task SetDateAsync(DateTime? date, bool updateValue)
{
if (_value != date)
{
if (date is not null && IsDateDisabled(date.Value.Date))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we risk a nullref exception if the func is set to null? I would suggest, make the default value of the func parameter null in the first place (meaning nothing is disabled) and call it only when it is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I added some logic to the prop to ensure the prop is always non-null and returns the "default"/safe value. I prefer this opposed to a nullable prop, but me me know if you really prefer a nullable prop and I'll be happy to change it.

Copy link
Contributor

@Yomodo Yomodo Jun 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who wants to PR a fix + test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henon, can you assign this to me.

@henon
Copy link
Collaborator

henon commented Jun 12, 2021

I love that you added a bunch of tests!

@jtwotimes jtwotimes requested a review from henon June 14, 2021 01:26
@henon
Copy link
Collaborator

henon commented Jun 17, 2021

This PR is ok by me. @tungi52, regarding the range picker you are the expert. can we merge?

@henon henon changed the title (feat): add IsDateDisabled functionality to MudDatePicker and MudDateRangePicker MudDatePicker and MudDateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates Jun 17, 2021
@henon henon changed the title MudDatePicker and MudDateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates Jun 17, 2021
Copy link
Contributor

@tungi52 tungi52 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henon Yes, from my side it is ok. @mtrdp642 nice work!

@henon henon merged commit cd4ca32 into MudBlazor:dev Jun 17, 2021
@henon henon added this to the 5.0.14 milestone Jun 17, 2021
}
set
{
if (value is null)
Copy link
Contributor

@Yomodo Yomodo Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I like a bit of space in my code, but surely the setter code can be condensed to a oneliner?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree and I would not write it like that myself. But I don't care enough ...
For me priorities are stability, maintainability, functional correctness and then some and personal coding preferneces are almost last.

Copy link
Contributor

@Yomodo Yomodo Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be a bit of code purist. Code should always be beautiful :)
But stability and maintainability should go first, agree yeah.

henon added a commit that referenced this pull request Jun 18, 2021
* Refined Drawer documentation.

* Added MudVirtualize, a Virtualize which can be switched off

* Fixed MudVirtualize API test

(cherry picked from commit c8bd5d1)

* Added Table Virtualization. (#796, #1847)

* Added Table Virtualization.

* Fix formatting...

* Missing @using for virtualize

* Use MudVirtualize instead of Virtualize

* Fixed MudVirtualize API test

* Removed unused usings

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>

* Autocomplete: Added Required parameter (#1499, #1829)

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835)

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* TabPanel: Allow HTML markup in Text (#1907, #1917)

* Add MarkupString for Tab text

* Added test case for html text tabs

Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>

* Docs: improved autocomplete validation example

* MudForm: improved the IsValid tow-way binding fix (previous fix was buggy)

* DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862)

* (feat): add IsDateDisabled functionality

* changed prop name to follow convention

* ensure prop can never be null

* fix default prop value

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: JJ Banda <=>

* Refined Drawer documentation.

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com>
Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>
Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com>
Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>
Co-authored-by: JJ Banda <mtrdp642@gmail.com>
henon added a commit that referenced this pull request Jun 20, 2021
* Fixes #1577

* Update README.md

* Fixes #1577

* Flips switch in RTL

* Added MudVirtualize, a Virtualize which can be switched off

* Fixed MudVirtualize API test

(cherry picked from commit c8bd5d1)

* Added Table Virtualization. (#796, #1847)

* Added Table Virtualization.

* Fix formatting...

* Missing @using for virtualize

* Use MudVirtualize instead of Virtualize

* Fixed MudVirtualize API test

* Removed unused usings

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>

* Autocomplete: Added Required parameter (#1499, #1829)

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835)

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* TabPanel: Allow HTML markup in Text (#1907, #1917)

* Add MarkupString for Tab text

* Added test case for html text tabs

Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>

* Docs: improved autocomplete validation example

* MudForm: improved the IsValid tow-way binding fix (previous fix was buggy)

* DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862)

* (feat): add IsDateDisabled functionality

* changed prop name to follow convention

* ensure prop can never be null

* fix default prop value

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: JJ Banda <=>

* Fixes #1577

* Refined Drawer documentation. (#1909)

* Refined Drawer documentation.

* Added MudVirtualize, a Virtualize which can be switched off

* Fixed MudVirtualize API test

(cherry picked from commit c8bd5d1)

* Added Table Virtualization. (#796, #1847)

* Added Table Virtualization.

* Fix formatting...

* Missing @using for virtualize

* Use MudVirtualize instead of Virtualize

* Fixed MudVirtualize API test

* Removed unused usings

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>

* Autocomplete: Added Required parameter (#1499, #1829)

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

* Added "Required" argument to Autocomplete

* Added MudAutocomplete and MudSelect unit tests for the Required attribute.

* Refined unit tests

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* MudSelect and MudAutocomplete: Adornment improvements (#804, #912, #1659, #1835)

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

* Select and Autocomplete improvements

* -Select Adornment.End now variable;
-Select/Autocomplete enabled AdornmentIcon;

* merge

* -Switched MudSelect and MudAutocomplete CloseIcon <> OpenIcon values;
-

* Switched MudSelect and MudAutocomplete CurrentIcon condition

* -Docs refinment: Added AdornmentIcon, CloseIcon and OpenIcon examples for MudSelect and MudAutocomplete;
-Docs refinment: Set ShowCode="false" for Variants example;

* -Autcomplete: Added call to UpdateIcon() from IsOpen.set and removed other calls to UpdateIcon;
-Removed test app;

* MudSelect: Added @attributes="UserAttributes" to satisfy unit test.

* Made CurrentIcon private and renamed to _currentIcon

* Removed test app

* -Changed method MudAutocomplete.UpdateIcon() to private;
-Changed method MudSelect.UpdateIcon() to private;
-Changed property MudSelect.CurrentIcon to private and renamed it to _currentIcon;

Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>

* TabPanel: Allow HTML markup in Text (#1907, #1917)

* Add MarkupString for Tab text

* Added test case for html text tabs

Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>

* Docs: improved autocomplete validation example

* MudForm: improved the IsValid tow-way binding fix (previous fix was buggy)

* DatePicker and DateRangePicker: add IsDateDisabledFunc to allow disabling selection of certain dates (#1862)

* (feat): add IsDateDisabled functionality

* changed prop name to follow convention

* ensure prop can never be null

* fix default prop value

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: JJ Banda <=>

* Refined Drawer documentation.

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com>
Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>
Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com>
Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>
Co-authored-by: JJ Banda <mtrdp642@gmail.com>

* Fixes #1577

* Fixes #1577

Co-authored-by: Meinrad Recheis <meinrad.recheis@gmail.com>
Co-authored-by: Jonas B <jonasmitb@gmail.com>
Co-authored-by: Terry Phillips <terry.w.phillips@gmail.com>
Co-authored-by: Jeffrey Jangli <adminjja@KPNWP.onmicrosoft.com>
Co-authored-by: aastovas <79198906+aastovas@users.noreply.github.com>
Co-authored-by: Alex Astovasadourian <asto.asto@edensoft.fr>
Co-authored-by: JJ Banda <mtrdp642@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants