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

MudForm and others: rename async methods #8875

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
CloseIcon="@Icons.Material.Filled.Search" AdornmentColor="Color.Tertiary"
Validation="@(new Func<string, IEnumerable<string>>(Validate))" />
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-auto mt-3 mb-3"
OnClick="@(()=>form.Validate())">Validate</MudButton>
OnClick="@(()=>form.ValidateAsync())">Validate</MudButton>
@if (form.IsTouched && form.IsValid)
{
<MudText Color="Color.Success">Success</MudText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

private async Task Submit()
{
await form.Validate();
await form.ValidateAsync();

if (form.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

private async Task Submit()
{
await form.Validate();
await form.ValidateAsync();

if (form.IsValid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</MudForm>
</MudPaper>
<MudPaper Class="pa-4 mt-4">
<MudButton Variant="Variant.Filled" Color="Color.Primary" DropShadow="false" OnClick="@(()=>form.Validate())">Validate</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" DropShadow="false" OnClick="@(()=>form.ValidateAsync())">Validate</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Secondary" DropShadow="false" OnClick="@(()=>form.ResetAsync())" Class="mx-2">Reset</MudButton>
<MudButton Variant="Variant.Filled" DropShadow="false" OnClick="@(()=>form.ResetValidation())">Reset Validation</MudButton>
<MudButton Variant="Variant.Filled" DropShadow="false" OnClick="@(()=>form.ResetValidationAsync())">Reset Validation</MudButton>
</MudPaper>
</MudItem>
<MudItem xs="12" sm="5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RequiredError="Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message. Very long error message."
ResetValueOnEmptyText="true" />
</MudForm>
<MudButton Variant="Variant.Filled" OnClick="@(()=>form.ResetValidation())">Reset Validation</MudButton>
<MudButton Variant="Variant.Filled" OnClick="@(()=>form.ResetValidationAsync())">Reset Validation</MudButton>
</MudItem>
</MudGrid>
@code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PickerActions>
</MudDateRangePicker>

<MudButton Class="mt-2" OnClick="@(() => _form.Validate())">Validate</MudButton>
<MudButton Class="mt-2" OnClick="@(() => _form.ValidateAsync())">Validate</MudButton>
</MudForm>

@code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<MudFileUpload T="IReadOnlyList<IBrowserFile>" For="@(() => Model.Files)" @bind-Files="Model.Files" />
</MudForm>

<MudButton OnClick="(() => Form.Validate())">Submit</MudButton>
<MudButton OnClick="(() => Form.ValidateAsync())">Submit</MudButton>
@code
{
public MudForm Form;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<MudTextField T="string" Required="true" Label="Last Name" />
</MudForm>
<div class="d-flex mt-5">
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(()=>form1.Validate())">Validate</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(()=>form1.ValidateAsync())">Validate</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="@(()=>form1.ResetAsync())" Class="mx-2">Reset</MudButton>
<MudButton Variant="Variant.Filled" OnClick="@(()=>form1.ResetValidation())">Reset Validation</MudButton>
<MudButton Variant="Variant.Filled" OnClick="@(()=>form1.ResetValidationAsync())">Reset Validation</MudButton>
</div>
<div class="d-flex mt-3">
<MudSwitch @bind-Value="@valid" Label="IsValid " Color="Color.Info" />
Expand Down
6 changes: 3 additions & 3 deletions src/MudBlazor.UnitTests/Components/AutocompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public async Task Autocomplete_Should_Validate_Data_Attribute_Fail()
autocomplete.Value.Should().Be("Quux");
autocomplete.Text.Should().Be("Quux");
// check validity
await comp.InvokeAsync(autocomplete.Validate);
await comp.InvokeAsync(autocomplete.ValidateAsync);
autocomplete.ValidationErrors.Should().NotBeEmpty();
autocomplete.ValidationErrors.Should().HaveCount(1);
autocomplete.ValidationErrors[0].Should().Be("Should not be longer than 3");
Expand All @@ -393,7 +393,7 @@ public async Task Autocomplete_Should_Validate_Data_Attribute_Success()
autocomplete.Value.Should().Be("Qux");
autocomplete.Text.Should().Be("Qux");
// check validity
await comp.InvokeAsync(autocomplete.Validate);
await comp.InvokeAsync(autocomplete.ValidateAsync);
autocomplete.ValidationErrors.Should().BeEmpty();
}

Expand All @@ -409,7 +409,7 @@ public async Task Autocomplete_Should_SetRequiredTrue()

autocomplete.Required.Should().BeTrue();

await comp.InvokeAsync(autocomplete.Validate);
await comp.InvokeAsync(autocomplete.ValidateAsync);

autocomplete.ValidationErrors.First().Should().Be("Required");
}
Expand Down
2 changes: 1 addition & 1 deletion src/MudBlazor.UnitTests/Components/DateRangePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public async Task DateRangePicker_RequiredValidation()
dateRangePickerInstance.DateRange.Should().Be(null);

// validated the picker
await dateRangePickerComponent.InvokeAsync(() => dateRangePickerInstance.Validate());
await dateRangePickerComponent.InvokeAsync(() => dateRangePickerInstance.ValidateAsync());
dateRangePickerInstance.Error.Should().BeTrue("Value is required and should be handled as invalid");
dateRangePickerInstance.ErrorText.Should().Be(errorMessage);

Expand Down
6 changes: 3 additions & 3 deletions src/MudBlazor.UnitTests/Components/FileUploadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public async Task FileUpload_ValidationTest()
var comp = Context.RenderComponent<FileUploadFormValidationTest>();

var form = comp.Instance.Form;
await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());

form.IsValid.Should().BeFalse(); //form is invalid to start

Expand All @@ -247,7 +247,7 @@ public async Task FileUpload_ValidationTest()
var singleInput = single.FindComponent<InputFile>();
singleInput.UploadFiles(fileContent[0]); //upload first file

await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());

single.Instance.ErrorText.Should().Be(null); //first input is now valid
single.Markup.Should().NotContain("'File' must not be empty.");
Expand All @@ -257,7 +257,7 @@ public async Task FileUpload_ValidationTest()
var multipleInput = multiple.FindComponent<InputFile>();
multipleInput.UploadFiles(fileContent); //upload second files

await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());

single.Instance.ErrorText.Should().Be(null); //second input is now valid
single.Markup.Should().NotContain("'Files' must not be empty.");
Expand Down
20 changes: 10 additions & 10 deletions src/MudBlazor.UnitTests/Components/FormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task FormIsTouchedTest()
form.IsTouched.Should().Be(true);

//reset validation should not reset touched state
await comp.InvokeAsync(() => form.ResetValidation());
await comp.InvokeAsync(() => form.ResetValidationAsync());
form.IsTouched.Should().Be(true);
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public async Task FormIsTouchedAndNestedFormIsNotTouchedWhenParentFormFieldIsTou
nestedForm.IsTouched.Should().Be(false);

//reset validation should not reset touched state
await comp.InvokeAsync(() => form.ResetValidation());
await comp.InvokeAsync(() => form.ResetValidationAsync());
form.IsTouched.Should().Be(true);
nestedForm.IsTouched.Should().Be(false);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task FormIsUnTouchedWhenNestedFormTouchedTest()
nestedForm.IsTouched.Should().Be(true);

//reset validation should not reset touched state
await comp.InvokeAsync(() => nestedFormDateField.ResetValidation());
await comp.InvokeAsync(() => nestedFormDateField.ResetValidationAsync());
form.IsTouched.Should().Be(false);
nestedForm.IsTouched.Should().Be(true);
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ public async Task MudFormExample_FillInValuesRootForm()
comp.FindAll("input")[5].Blur();

var form = comp.FindComponent<MudForm>().Instance;
await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());
form.IsValid.Should().BeFalse();

var textfields = comp.FindComponents<MudTextField<string>>();
Expand Down Expand Up @@ -1242,7 +1242,7 @@ public async Task MudFormExample_FillInValuesNestedForm()
comp.FindAll("input")[9].Blur();

var form = comp.FindComponent<MudForm>().Instance;
await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());
form.IsValid.Should().BeFalse();

var textfields = comp.FindComponents<MudTextField<string>>();
Expand Down Expand Up @@ -1297,7 +1297,7 @@ public async Task MudFormExample_FillInValues()
comp.FindAll("input")[9].Blur();

var form = comp.FindComponent<MudForm>().Instance;
await comp.InvokeAsync(() => form.Validate());
await comp.InvokeAsync(() => form.ValidateAsync());
form.IsValid.Should().BeTrue();

var textfields = comp.FindComponents<MudTextField<string>>();
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public async Task MudFormComponent_ValidationWithModel_UnexpectedErrorInValidati
tf.SetParam(nameof(MudTextField<string>.Validation), validationFunc);
Expression<Func<string>> expression = () => model.data;
tf.SetParam(nameof(MudTextField<string>.For), expression);
await comp.InvokeAsync(tf.Instance.Validate);
await comp.InvokeAsync(tf.Instance.ValidateAsync);
tf.Instance.Error.Should().Be(true);
tf.Instance.ErrorText.Should().Be("Error in validation func: User error");
}
Expand All @@ -1369,7 +1369,7 @@ public async Task MudFormComponent_ValidationWithModelWithNoFor_ShouldShow_Expec
throw new InvalidOperationException("User error");
});
tf.SetParam(nameof(MudTextField<string>.Validation), validationFunc);
await comp.InvokeAsync(tf.Instance.Validate);
await comp.InvokeAsync(tf.Instance.ValidateAsync);
tf.Instance.Error.Should().Be(true);
tf.Instance.ErrorText.Should().Be("For is null, please set parameter For on the form input component of type MudTextField`1");
}
Expand All @@ -1391,7 +1391,7 @@ public async Task MudFormComponent_AsyncValidationWithModelWithNoFor_ShouldShow_
throw new InvalidOperationException("User error");
});
tf.SetParam(nameof(MudTextField<string>.Validation), validationFunc);
await comp.InvokeAsync(tf.Instance.Validate);
await comp.InvokeAsync(tf.Instance.ValidateAsync);
tf.Instance.Error.Should().Be(true);
tf.Instance.ErrorText.Should().Be("For is null, please set parameter For on the form input component of type MudTextField`1");
}
Expand All @@ -1416,7 +1416,7 @@ public async Task MudFormComponent_ValidationWithModel_UnexpectedErrorInValidati
tf.SetParam(nameof(MudTextField<string>.Validation), validationFunc);
Expression<Func<string>> expression = () => model.data;
tf.SetParam(nameof(MudTextField<string>.For), expression);
await comp.InvokeAsync(tf.Instance.Validate);
await comp.InvokeAsync(tf.Instance.ValidateAsync);
tf.Instance.Error.Should().Be(true);
tf.Instance.ErrorText.Should().Be("Error1");
}
Expand Down
2 changes: 1 addition & 1 deletion src/MudBlazor.UnitTests/Components/NumericFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public async Task NumericField_Validation<T>(T value)
numericField.Value.Should().Be(value);
await comp.InvokeAsync(() =>
{
numericField.Validate().Wait();
numericField.ValidateAsync().Wait();
});
numericField.Value.Should().Be(value);
}
Expand Down
14 changes: 7 additions & 7 deletions src/MudBlazor.UnitTests/Components/SelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public async Task TextField_Should_Validate_Data_Attribute_Fail()
select.Value.Should().Be("Quux");
select.Text.Should().Be("Quux");
// check validity
await comp.InvokeAsync(() => select.Validate());
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.Should().NotBeEmpty();
select.ValidationErrors.Should().HaveCount(1);
select.ValidationErrors[0].Should().Be("Should not be longer than 3");
Expand All @@ -742,7 +742,7 @@ public async Task TextField_Should_Validate_Data_Attribute_Success()
select.Value.Should().Be("Qux");
select.Text.Should().Be("Qux");
// check validity
await comp.InvokeAsync(() => select.Validate());
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.Should().BeEmpty();
}
#endregion
Expand All @@ -756,7 +756,7 @@ public async Task Select_Should_SetRequiredTrue()
var comp = Context.RenderComponent<SelectRequiredTest>();
var select = comp.FindComponent<MudSelect<string>>().Instance;
select.Required.Should().BeTrue();
await comp.InvokeAsync(() => select.Validate());
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.First().Should().Be("Required");
}

Expand Down Expand Up @@ -1136,21 +1136,21 @@ public async Task MultiSelectWithRequiredValue()
var comp = Context.RenderComponent<MultiSelectTestRequiredValue>();
var select = comp.FindComponent<MudSelect<string>>().Instance;
select.Required.Should().BeTrue();
await comp.InvokeAsync(() => select.Validate());
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.First().Should().Be("Required");

//1b. Check on T type - MultiSelect of T(e.g. class object)
var selectWithT = comp.FindComponent<MudSelect<MultiSelectTestRequiredValue.TestClass>>().Instance;
selectWithT.Required.Should().BeTrue();
await comp.InvokeAsync(() => selectWithT.Validate());
await comp.InvokeAsync(() => selectWithT.ValidateAsync());
selectWithT.ValidationErrors.First().Should().Be("Required");

//2a. Now check when SelectedItems is greater than one - Validation Should Pass
var inputs = comp.FindAll("div.mud-input-control");
inputs[0].Click();//The 2nd one is the
var items = comp.FindAll("div.mud-list-item").ToArray();
items[1].Click();
await comp.InvokeAsync(() => select.Validate());
await comp.InvokeAsync(() => select.ValidateAsync());
select.ValidationErrors.Count.Should().Be(0);

//2b.
Expand All @@ -1159,7 +1159,7 @@ public async Task MultiSelectWithRequiredValue()
comp.WaitForState(() => comp.FindAll("div.mud-list-item").Count == 5);
items = comp.FindAll("div.mud-list-item").ToArray();
items[3].Click();
await comp.InvokeAsync(() => selectWithT.Validate());
await comp.InvokeAsync(() => selectWithT.ValidateAsync());
selectWithT.ValidationErrors.Count.Should().Be(0);
}

Expand Down