Skip to content

Commit 85944f0

Browse files
committed
chore: update listview validation example
1 parent ec4e40c commit 85944f0

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

listview/ValidationExamples/ValidationExamples/Pages/AsyncMethods.razor

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99
<EditTemplate>
1010
<div style="border: 1px solid green; margin: 10px; padding: 10px; display: inline-block;">
1111
@{
12-
currEditItem = context;
13-
if (isEditing && currEditContext == null)
12+
if (currEditContext == null || context != currEditItem)
1413
{
15-
currEditContext = new EditContext(currEditItem);
14+
currEditContext = new EditContext(context);
1615
}
16+
currEditItem = context;
1717

1818
if (currEditContext != null)
1919
{
2020
<EditForm EditContext="@currEditContext" Context="formContext">
2121
<DataAnnotationsValidator />
22-
<TelerikTextBox @bind-Value="@currEditItem.Name" Label="Name" />
22+
<label for="name">Name</label>
23+
<TelerikTextBox Id="name" @bind-Value="@currEditItem.Name" />
2324
<ValidationMessage For="@(() => currEditItem.Name)"></ValidationMessage>
2425

2526
<br />
26-
<TelerikDropDownList Data="@Teams" @bind-Value="@currEditItem.Team" />
27+
<label for="team">Team</label>
28+
<TelerikDropDownList Id="team" Data="@Teams" @bind-Value="@currEditItem.Team" />
2729

2830
<ListViewCommandButton Command="Save" Icon="save">Save</ListViewCommandButton>
2931
<ListViewCommandButton Command="Cancel" Icon="cancel">Cancel</ListViewCommandButton>

listview/ValidationExamples/ValidationExamples/Pages/BasicFormValidation.razor

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@
77
@using System.ComponentModel.DataAnnotations
88

99
<TelerikListView Data="@ListViewData" Pageable="true"
10-
OnCreate="@CreateHandler" OnDelete="@DeleteHandler" OnUpdate="@UpdateHandler" OnCancel="@CancelHandler">
10+
OnCreate="@CreateHandler" OnDelete="@DeleteHandler" OnUpdate="@UpdateHandler">
1111
<EditTemplate>
1212
<div style="border: 1px solid green; margin: 10px; padding: 10px; display: inline-block;">
1313
@{
14-
currEditItem = context;
15-
if (currEditContext == null)
14+
if (currEditContext == null || context != currEditItem)
1615
{
17-
currEditContext = new EditContext(currEditItem);
16+
currEditContext = new EditContext(context);
1817
}
18+
currEditItem = context;
19+
1920
<EditForm EditContext="@currEditContext" Context="formContext">
2021
<DataAnnotationsValidator />
21-
<TelerikTextBox @bind-Value="@currEditItem.Name" Label="Name" />
22+
<label for="name">Name</label>
23+
<TelerikTextBox Id="name" @bind-Value="@currEditItem.Name" />
2224
<ValidationMessage For="@(() => currEditItem.Name)"></ValidationMessage>
2325

2426
<br />
25-
<TelerikDropDownList Data="@Teams" @bind-Value="@currEditItem.Team" />
27+
<label for="team">Team</label>
28+
<TelerikDropDownList Id="team" Data="@Teams" @bind-Value="@currEditItem.Team" />
2629

2730
<ListViewCommandButton Command="Save" Icon="save">Save</ListViewCommandButton>
2831
<ListViewCommandButton Command="Cancel" Icon="cancel">Cancel</ListViewCommandButton>
@@ -68,8 +71,6 @@
6871
// update the view-model, can use returned data from the remote service too
6972
insertedItem.Id = ListViewData.Count + 1;
7073
ListViewData.Insert(0, insertedItem);
71-
72-
CleanUpValidation();
7374
}
7475

7576
async Task DeleteHandler(ListViewCommandEventArgs e)
@@ -104,20 +105,6 @@
104105
{
105106
ListViewData[index] = updatedItem;
106107
}
107-
108-
CleanUpValidation();
109-
}
110-
111-
void CancelHandler(ListViewCommandEventArgs e)
112-
{
113-
CleanUpValidation();
114-
}
115-
116-
void CleanUpValidation()
117-
{
118-
// clean up for next run
119-
currEditContext = null;
120-
currEditItem = null;
121108
}
122109

123110
// data and models follow

listview/ValidationExamples/ValidationExamples/Pages/CustomForm.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
<DataAnnotationsValidator />
4040
<div class="form-row">
4141
<div class="col">
42-
<TelerikTextBox @bind-Value="@CurrentlyEditedItem.Name" Label="First Name"></TelerikTextBox>
42+
<label for="name">Name</label>
43+
<TelerikTextBox Id="name" @bind-Value="@CurrentlyEditedItem.Name" ></TelerikTextBox>
4344
</div>
4445
<div class="col">
45-
<TelerikTextBox @bind-Value="@CurrentlyEditedItem.Team" Label="Team"></TelerikTextBox>
46+
<label for="team">Team</label>
47+
<TelerikTextBox Id="team" @bind-Value="@CurrentlyEditedItem.Team" ></TelerikTextBox>
4648
</div>
4749
</div>
4850
<div class="form-row">

listview/ValidationExamples/ValidationExamples/ValidationExamples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.4.0" />
8+
<PackageReference Include="Telerik.UI.for.Blazor" Version="3.6.0" />
99
</ItemGroup>
1010

1111
</Project>

0 commit comments

Comments
 (0)