Skip to content

Commit f548d6d

Browse files
committed
feat: add support for non-nullable components with DateOrToday and TimeOrNow properties in LocalTimeForm
1 parent 3024920 commit f548d6d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

example/BlazorLocalTimeSample/Pages/Home.razor

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,33 @@
147147
</LocalTimeForm>
148148
</div>
149149

150+
<p>
151+
If you want to use non-nullable components or create a form that sets the current date and time as the initial value,
152+
you can use the <code>DateOrToday</code> and <code>TimeOrNow</code> properties.
153+
</p>
154+
<pre><code class="language-razor">Value: @@(Dt?.ToString("yyyy-MM-dd HH:mm:ssK") ?? "Not specified yet")
155+
&lt;br /&gt;
156+
&lt;LocalTimeForm @@bind-Value="Dt" Context="dtf"&gt;
157+
&lt;InputDate Type="InputDateType.Date" @@bind-Value="dtf.DateOrToday" /&gt;
158+
&lt;InputDate Type="InputDateType.Time" @@bind-Value="dtf.TimeOrNow" /&gt;
159+
&lt;button @@onclick="() =&gt; Dt = null"&gt;Reset&lt;/button&gt;
160+
&lt;/LocalTimeForm&gt;
161+
162+
@@code {
163+
private DateTime? Dt { get; set; } = DateTime.UtcNow;
164+
}
165+
</code></pre>
166+
167+
<div class="component-sample">
168+
Value: @(Dt2?.ToString("yyyy-MM-dd HH:mm:ssK") ?? "Not specified yet")
169+
<br />
170+
<LocalTimeForm @bind-Value="Dt2" Context="dtf">
171+
<InputDate Type="InputDateType.Date" @bind-Value="dtf.DateOrToday" />
172+
<InputDate Type="InputDateType.Time" @bind-Value="dtf.TimeOrNow" />
173+
<button @onclick="() => Dt2 = null">Reset</button>
174+
</LocalTimeForm>
175+
</div>
176+
150177
<h2>Using with UI Libraries</h2>
151178

152179
<p>
@@ -321,6 +348,7 @@ Current Time: &lt;LocalTimeText Value="@@DateTime.UtcNow" Format="yyyy-MM-dd HH:
321348
@inject ILocalTimeService LocalTimeService
322349
@code {
323350
private DateTime? Dt { get; set; } = DateTime.UtcNow;
351+
private DateTime? Dt2 { get; set; }
324352

325353
private DateTimeOffset? LocalDt { get; set; }
326354
private void ButtonClicked()

0 commit comments

Comments
 (0)