@@ -185,5 +185,59 @@
")>
-
-
\ No newline at end of file
+
+
+
+
In an edit form with a Data Annotation Validator
+
+
+
+
+
+
+ Submit
+
+ @code
+ {
+ class AutocompleteContextModel
+ {
+ public List Options { get; set; } = new List() { "A test option", "Another test option", "One more option" };
+
+ [System.ComponentModel.DataAnnotations.Required]
+ public string SelectedOption { get; set; }
+ }
+ AutocompleteContextModel model = new AutocompleteContextModel();
+
+ void HandleValidSubmit()
+ {
+ Console.WriteLine("On Valid Submit");
+ }
+ }
+
+
+
+
+
+
+ Submit
+
+ @code
+ {
+ class AutocompleteContextModel
+ {
+ public List Options { get; set; } = new List() { ""A test option"", ""Another test option"", ""One more option"" };
+
+ [System.ComponentModel.DataAnnotations.Required]
+ public string SelectedOption { get; set; }
+ }
+ AutocompleteContextModel model = new AutocompleteContextModel();
+
+ void HandleValidSubmit()
+ {
+ Console.WriteLine(""On Valid Submit"");
+ }
+ }
+ ")>
+
+
diff --git a/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs b/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs
index 8a701433..4f904a2b 100644
--- a/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs
+++ b/src/MatBlazor/Components/MatAutocompleteList/BaseMatAutocompleteList.cs
@@ -90,10 +90,13 @@ public TItem Value
get { return _value; }
set
{
- var newerStringValue = EqualValues(value, default) ? string.Empty : ComputeStringValue(value);
- if (newerStringValue != StringValue)
+ if (!EqualValues(value, default))
{
- StringValue = newerStringValue;
+ var newValue = ComputeStringValue(value);
+ if (newValue != StringValue)
+ {
+ StringValue = newValue;
+ }
}
if (EqualValues(value, _value))
@@ -175,6 +178,7 @@ protected void ClosePopup()
if (StringValue != ComputeStringValue(Value))
{
_value = default;
+ ValueChanged.InvokeAsync(_value);
}
IsOpened = false;
}
@@ -190,7 +194,6 @@ public async void OnKeyDown(KeyboardEventArgs ev)
if (ev.Key == "ArrowDown" || ev.Key == "ArrowUp")
{
int currentIndex = await ListRef.GetSelectedIndex();
- int nextIndex = (ev.Key == "ArrowDown") ? currentIndex++ : currentIndex--;
await ListRef.SetSelectedIndex(currentIndex);
}
else if (ev.Key == "Enter")
diff --git a/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor b/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor
index eeacf4be..b571f480 100644
--- a/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor
+++ b/src/MatBlazor/Components/MatAutocompleteList/MatAutocompleteList.razor
@@ -5,11 +5,23 @@
-
+
@if (IsShowingClearButton)
{
-
+
}
@if (Items != null && IsOpened)