Skip to content

Commit

Permalink
fixed #631 [HxInputDate] throws InvalidOperationException: JavaScript…
Browse files Browse the repository at this point in the history
… interop calls cannot be issued
  • Loading branch information
hakenr committed Oct 19, 2023
1 parent c4479f0 commit 9416a03
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
23 changes: 23 additions & 0 deletions BlazorAppTest/Pages/HxInputDate_Issue631_Test.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@page "/HxInputDate_Issue631_Test"
@using Havit;

<h1>HxInputDate</h1>

<HxCard>
<HeaderTemplate><HxIcon Icon="@BootstrapIcon.Calendar4Range" />&ensp;Date Range</HeaderTemplate>
<BodyTemplate>
<div class="row">
<div class="col-6">
<HxInputDate Label="Start" @bind-Value="@startDate" MaxDate="@DateTime.Today" />
</div>
<div class="col-6">
<HxInputDate Label="End" @bind-Value="@endDate" MaxDate="@DateTime.Today" />
</div>
</div>
</BodyTemplate>
</HxCard>

@code {
private DateTime startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
private DateTime endDate = DateTime.Today;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class HxInputDateInternal<TValue> : InputBase<TValue>, IAsyncDisp
[Parameter] public bool EnabledEffective { get; set; } = true;

[Parameter] public bool ShowPredefinedDatesEffective { get; set; }

[Parameter] public IEnumerable<InputDatePredefinedDatesItem> PredefinedDatesEffective { get; set; }

[Parameter] public string ParsingErrorMessageEffective { get; set; }
Expand Down Expand Up @@ -59,7 +60,6 @@ public partial class HxInputDateInternal<TValue> : InputBase<TValue>, IAsyncDisp


[Inject] protected IStringLocalizerFactory StringLocalizerFactory { get; set; }

[Inject] protected IJSRuntime JSRuntime { get; set; }

protected bool HasInputGroupsEffective => !String.IsNullOrWhiteSpace(InputGroupStartText) || !String.IsNullOrWhiteSpace(InputGroupEndText) || (InputGroupStartTemplate is not null) || (InputGroupEndTemplate is not null);
Expand All @@ -76,6 +76,7 @@ public partial class HxInputDateInternal<TValue> : InputBase<TValue>, IAsyncDisp
private HxDropdownToggleElement hxDropdownToggleElement;
private ElementReference iconWrapperElement;
private IJSObjectReference jsModule;
private bool firstRenderCompleted;

protected override void OnParametersSet()
{
Expand Down Expand Up @@ -127,6 +128,8 @@ protected override bool TryParseValueFromString(string value, out TValue result,

protected override async Task OnAfterRenderAsync(bool firstRender)
{
firstRenderCompleted = true;

await base.OnAfterRenderAsync(firstRender);

if (RenderIcon)
Expand Down Expand Up @@ -233,14 +236,17 @@ protected virtual async ValueTask DisposeAsyncCore()

try
{
if (hxDropdownToggleElement is not null)
{
await CloseDropdownAsync();
}

if (jsModule is not null)
if (firstRenderCompleted)
{
await jsModule.DisposeAsync();
if (hxDropdownToggleElement is not null)
{
await CloseDropdownAsync();
}

if (jsModule is not null)
{
await jsModule.DisposeAsync();
}
}
}
catch (JSDisconnectedException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public partial class HxInputDateRangeInternal : InputBase<DateTimeRange>, IAsync

[Inject] protected IStringLocalizerFactory StringLocalizerFactory { get; set; }

[Inject] protected IJSRuntime JSRuntime { get; set; }

private DateTimeRange previousValue;
private bool fromPreviousParsingAttemptFailed;
private bool toPreviousParsingAttemptFailed;
Expand All @@ -47,6 +45,8 @@ public partial class HxInputDateRangeInternal : InputBase<DateTimeRange>, IAsync
private HxDropdownToggleElement fromDropdownToggleElement;
private HxDropdownToggleElement toDropdownToggleElement;

private bool firstRenderCompleted;

protected override void OnParametersSet()
{
base.OnParametersSet();
Expand All @@ -65,6 +65,11 @@ protected override void OnParametersSet()
}
}

protected override void OnAfterRender(bool firstRender)
{
firstRenderCompleted = true;
}

protected override bool TryParseValueFromString(string value, out DateTimeRange result, out string validationErrorMessage)
{
throw new NotSupportedException();
Expand Down Expand Up @@ -244,21 +249,24 @@ protected virtual async ValueTask DisposeAsyncCore()
{
validationMessageStore?.Clear();

try
if (firstRenderCompleted)
{
if (fromDropdownToggleElement is not null)
try
{
await CloseDropdownAsync(fromDropdownToggleElement);
if (fromDropdownToggleElement is not null)
{
await CloseDropdownAsync(fromDropdownToggleElement);
}
if (toDropdownToggleElement is not null)
{
await CloseDropdownAsync(toDropdownToggleElement);
}
}
if (toDropdownToggleElement is not null)
catch (JSDisconnectedException)
{
await CloseDropdownAsync(toDropdownToggleElement);
// NOOP
}
}
catch (JSDisconnectedException)
{
// NOOP
}

Dispose(false);
}
Expand Down
3 changes: 2 additions & 1 deletion exclusion.dic
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Autoplay
autoplay
autoplays
Blazor
gRPC
hoverable
Expand Down

0 comments on commit 9416a03

Please sign in to comment.