Skip to content

Commit

Permalink
Fix the init issue when we have initial date for picker set dynamically
Browse files Browse the repository at this point in the history
#60 + Up to 3.2.0
  • Loading branch information
farshaddavoudi committed Nov 21, 2023
1 parent 7fa17bf commit 99f97c9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ It is compatible and installable on all .NET5, .NET6 and .NET7 Blazor projects
PickerOffsetTopPositionInPixels="2" //Default: 2
// Initial value for input set on today
InitialValue="false" //Default: false
InitialValueSetOnToday="false" //Default: false
// Calendar type for date picker including Dual, Single, etc
// Options: Calendar.DualModeJalaliDefault | Calendar.DualModeMiladiDefault | Calendar.SingleModeJalali | Calendar.SingleModeMiladi
Expand Down Expand Up @@ -112,7 +112,7 @@ It is compatible and installable on all .NET5, .NET6 and .NET7 Blazor projects
Disabled="false"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="1"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.SingleModeJalali"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand Down
8 changes: 4 additions & 4 deletions samples/BlazorServer/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Welcome to your new app.
Disabled="false"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="-5"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.DualModeJalaliDefault"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand All @@ -35,7 +35,7 @@ Welcome to your new app.
Disabled="false"
PickerAlign="Align.Left"
PickerOffsetTopPositionInPixels="25"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.DualModeMiladiDefault"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_dash_MM_dash_dd"
Expand All @@ -59,7 +59,7 @@ Welcome to your new app.
Disabled="false"
PickerAlign="Align.Left"
PickerOffsetTopPositionInPixels="0"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.SingleModeJalali"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand All @@ -80,7 +80,7 @@ Welcome to your new app.
Disabled="false"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="1"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.SingleModeMiladi"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand Down
26 changes: 22 additions & 4 deletions samples/BlazorWebAssembly/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Visible="true"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="0"
InitialValue="true"
InitialValueSetOnToday="true"
ShowCalendarIcon="true"
CalendarType="Calendar.DualModeJalaliDefault"
DigitType="DigitType.BasedOnCalendar"
Expand All @@ -35,7 +35,7 @@
PickerAlign="Align.Left"
ShowCalendarIcon="false"
PickerOffsetTopPositionInPixels="25"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.DualModeMiladiDefault"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_dash_MM_dash_dd"
Expand All @@ -56,7 +56,7 @@
ShowCalendarIcon="false"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="0"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.SingleModeJalali"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand All @@ -78,7 +78,7 @@
Disabled="false"
PickerAlign="Align.Right"
PickerOffsetTopPositionInPixels="1"
InitialValue="false"
InitialValueSetOnToday="false"
CalendarType="Calendar.SingleModeMiladi"
DigitType="DigitType.BasedOnCalendar"
DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
Expand All @@ -88,6 +88,17 @@
Style="border:1px solid green; width:20%; float:right"
Theme="PickerTheme.RedBlack"
OnChange="@(() => Console.WriteLine($"OK4 - {_variable4}"))" />

<br />
<br />
<br />

<div style="display: flex; border: 1px solid green;justify-content: space-around; padding: 50px">
<b> Val1= @_variable1 </b>
<b> Val2= @_variable2 </b>
<b> Val3= @_variable3 </b>
<b> Val4= @_variable4 </b>
</div>

@*<label style="float: right; font-size: 25px; font-weight:bold"> @_myComponentPrivateField </label>*@

Expand All @@ -97,4 +108,11 @@
private string _variable2;
private string _variable3;
private string _variable4;

protected override void OnInitialized()
{
_variable3 = "۱۴۰۲/۱۱/۱۱";

base.OnInitialized();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<Version>3.1.1</Version>
<Version>3.2.0</Version>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);NU1701;1702;1591;NU1602;CS8609;CS8610;CS8619;CS8632</NoWarn>
<Nullable>enable</Nullable>
Expand Down
9 changes: 5 additions & 4 deletions src/Blazor.PersianDatePicker/InputPersianDatePicker.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@if (Visible)
{
<div class="datepicker_wrapp" style="@Style">
<input id="@Id"
<input id="@Id"
name="@Name"
readonly="@ReadOnly"
disabled="@Disabled"
Expand All @@ -11,6 +11,7 @@
autocomplete="off"
maxlength="10"
value="@Value"
init-value="@Value"
@onchange="@Change" />
<span class="@_clearBtnCssClass" @onclick="@Clear">×</span>
</div>
Expand Down Expand Up @@ -104,7 +105,7 @@
/// Initial value for input set on today
/// </summary>
[Parameter]
public bool InitialValue { get; set; }
public bool InitialValueSetOnToday { get; set; }

/// <summary>
/// Calendar type for date picker including Dual, Single, etc
Expand Down Expand Up @@ -213,7 +214,7 @@
}
}

if (InitialValue)
if (InitialValueSetOnToday)
{
var dt = DateTime.Now;

Expand Down Expand Up @@ -278,7 +279,7 @@
enableSwitchCalendar,
hasExplicitDigitType,
digitType,
InitialValue,
InitialValueSetOnToday,
DateFormat.ToEnumDisplayName()!,
minDate ?? string.Empty,
PickerAlign.ToString().ToLower(),
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.PersianDatePicker/wwwroot/datepicker.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ try {
key: "getOnInitState",
value: function () {
var e = null, t = Zepto(this.elem), n = void 0;
if ((n = "INPUT" === t[0].nodeName ? t[0].getAttribute("value") : t.data("date")) && n.match("^([0-1][0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9]))?$")) {
if ((n = "INPUT" === t[0].nodeName ? t[0].getAttribute("init-value") : t.data("date")) && n.match("^([0-1][0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9]))?$")) {
var i = n.split(":"), a = new Date();
a.setHours(i[0]), a.setMinutes(i[1]), i[2] ? a.setSeconds(i[2]) : a.setSeconds(0),
this.initialUnix = a.valueOf();
Expand Down

0 comments on commit 99f97c9

Please sign in to comment.