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

Improve AbpDatePicker #18648

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/en/UI/AspNetCore/Tag-Helpers/Form-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ You can set some of the attributes on your c# property, or directly on HTML tag.
* `single-open-and-clear-button`: Shows the open and clear buttons in a single button when it's `True`. The default value is `True`.
* `is-utc`: Converts the date to UTC when its `True`. The default value is `False`.
* `is-iso`: Converts the date to ISO format when its `True`. The default value is `False`.
* `date-format`: Sets the date format of the input. The default format is the user's culture date format. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `visible-date-format`: Sets the date format of the input. The default format is the user's culture date format. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `input-date-format`: Sets the date format of the hidden input for backend compatibility. The default format is `YYYY-MM-DD`. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `date-separator`: Sets a character to separate start and end dates. The default value is `-`
* Other non-mapped attributes will be automatically added to the input element as is. See the available [datepicker options](https://www.daterangepicker.com/#options). Eg: `data-start-date="2020-01-01"`

Expand Down Expand Up @@ -425,7 +426,8 @@ newPicker.insertAfter($('body'));
* `singleOpenAndClearButton`: Shows the open and clear buttons in a single button when it's `True`. The default value is `True`.
* `isUtc`: Converts the date to UTC when its `True`. The default value is `False`.
* `isIso`: Converts the date to ISO format when its `True`. The default value is `False`.
* `dateFormat`: Sets the date format of the input. The default format is the user's culture date format. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `visibleDateFormat`: Sets the date format of the input. The default format is the user's culture date format. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `inputDateFormat`: Sets the date format of the hidden input for backend compatibility. The default format is `YYYY-MM-DD`. You need to provide a JavaScript date format convention. Eg: `YYYY-MM-DDTHH:MM:SSZ`.
* `dateSeparator`: Sets a character to separate start and end dates. The default value is `-`.
* `startDateName`: Sets the name of the hidden start date input.
* `endDateName`: Sets the name of the hidden end date input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,28 @@ public void SetDatePickerOptions(IAbpDatePickerOptions options)
set => _abpDatePickerOptionsImplementation.ParentEl = value;
}

[Obsolete("Use VisibleDateFormat instead.")]
public string? DateFormat {
get => _abpDatePickerOptionsImplementation.DateFormat;
set => _abpDatePickerOptionsImplementation.DateFormat = value;
}

public string? VisibleDateFormat {
get => _abpDatePickerOptionsImplementation.VisibleDateFormat;
set => _abpDatePickerOptionsImplementation.VisibleDateFormat = value;
}

public string? InputDateFormat {
get => _abpDatePickerOptionsImplementation.InputDateFormat;
set => _abpDatePickerOptionsImplementation.InputDateFormat = value;
}

public bool OpenButton {
get => _abpDatePickerOptionsImplementation.OpenButton;
set => _abpDatePickerOptionsImplementation.OpenButton = value;
}

public bool ClearButton {
public bool? ClearButton {
get => _abpDatePickerOptionsImplementation.ClearButton;
set => _abpDatePickerOptionsImplementation.ClearButton = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async override Task ProcessAsync(TagHelperContext context, TagHelperOutpu
var openButtonContent = TagHelper.OpenButton
? await ProcessButtonAndGetContentAsync(context, output, "calendar", "open")
: "";
var clearButtonContent = TagHelper.ClearButton
var clearButtonContent = TagHelper.ClearButton == true || (!TagHelper.ClearButton.HasValue && TagHelper.AutoUpdateInput != true)
? await ProcessButtonAndGetContentAsync(context, output, "times", "clear", visible:!TagHelper.SingleOpenAndClearButton)
: "";

Expand Down Expand Up @@ -382,6 +382,16 @@ protected TagHelperAttributeList ConvertDatePickerOptionsToAttributeList(IAbpDat
{
attrList.Add("data-date-format", options.DateFormat);
}

if(!options.VisibleDateFormat.IsNullOrEmpty())
{
attrList.Add("data-visible-date-format", options.VisibleDateFormat);
}

if(!options.InputDateFormat.IsNullOrEmpty())
{
attrList.Add("data-input-date-format", options.InputDateFormat);
}

if(options.Ranges != null && options.Ranges.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ public class AbpDatePickerOptions : IAbpDatePickerOptions
public bool? LinkedCalendars { get; set; }
public bool? AutoUpdateInput { get; set; }
public string? ParentEl { get; set; }

[Obsolete("Use VisibleDateFormat instead.")]
public string? DateFormat { get; set; }
public string? VisibleDateFormat { get; set; }
public string? InputDateFormat { get; set; }
public bool OpenButton { get; set; } = true;
public bool ClearButton { get; set; } = true;
public bool? ClearButton { get; set; }
public bool SingleOpenAndClearButton { get; set; } = true;
public bool? IsUtc { get; set; }
public bool? IsIso { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,24 @@ protected override int GetOrder()

protected override void AddBaseTagAttributes(TagHelperAttributeList attributes)
{
if (TagHelper.AspForStart != null &&
TagHelper.AspForStart.Model != null &&
if (TagHelper.AspForStart?.Model != null &&
SupportedInputTypes.TryGetValue(TagHelper.AspForStart.Metadata.ModelType, out var convertFuncStart))
{
attributes.Add("data-start-date", convertFuncStart(TagHelper.AspForStart.Model));
var convert = convertFuncStart(TagHelper.AspForStart.Model);
if(!convert.IsNullOrWhiteSpace())
{
attributes.Add("data-start-date", convert);
}
}

if (TagHelper.AspForEnd != null &&
TagHelper.AspForEnd.Model != null &&

if (TagHelper.AspForEnd?.Model != null &&
SupportedInputTypes.TryGetValue(TagHelper.AspForEnd.Metadata.ModelType, out var convertFuncEnd))
{
attributes.Add("data-end-date", convertFuncEnd(TagHelper.AspForEnd.Model));
var convert = convertFuncEnd(TagHelper.AspForEnd.Model);
if(!convert.IsNullOrWhiteSpace())
{
attributes.Add("data-end-date", convert);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,22 @@ public interface IAbpDatePickerOptions
/// </summary>
string? ParentEl { get; set; }

[Obsolete("Use VisibleDateFormat instead.")]
string? DateFormat { get; set; }

/// <summary>
/// The date format string that will appear in the input element. For user input.
/// </summary>
string? VisibleDateFormat { get; set; }

/// <summary>
/// The date format string that will appear in the hidden input element. For backend compatibility.
/// </summary>
string? InputDateFormat { get; set; }

bool OpenButton { get; set; }

bool ClearButton { get; set; }
bool? ClearButton { get; set; }

bool SingleOpenAndClearButton { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/modal-manager.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/sweetalert2/abp-sweetalert2.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js"
"/libs/abp/aspnetcore-mvc-ui-theme-shared/toastr/abp-toastr.js",
"/libs/abp/aspnetcore-mvc-ui-theme-shared/date-range-picker/date-range-picker-extensions.js"

Check warning on line 52 in framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs#L51-L52

Added lines #L51 - L52 were not covered by tests
});
}
}