ModelPropertyChanged doesn't seem to update with Select control in CSLA 5 #2747
-
I've created a custom drop down component from a select and similar to the TextInput component, I'm binding it to a private property that gets and sets the inputted PropertyInfo parameter: <div class="row mb-3">
<label for="@Id" class="col-sm-3 col-md-2 col-form-label">@Property.FriendlyName</label>
<div class="col-sm-9 col-md-10">
<select @bind="Value" id="@Id"
disabled="@(!Property.CanWrite)" class="form-select" >
@foreach (var item in DataItems)
{
<option value="@item.Id">@item.Name</option>
}
</select>
<div class="text-danger mt-2">@Property.ErrorText</div>
<div class="text-warning mt-2">@Property.WarningText</div>
<div class="text-info mt-2">@Property.InformationText</div>
</div>
</div>
@code {
[Parameter]
public Csla.Blazor.IPropertyInfo Property { get; set; } = default!;
[Parameter]
public string Id { get; set; } = $"ctrl{Guid.NewGuid()}";
private int? Value
{
get => (int?)Property.Value;
set
{
Property.Value = value;
}
}
} Then in my razor page I'm adding this control, and in the OnInitialize method I'm setting up the ModelPropertyChanged event: protected async override Task OnInitializedAsync()
{
await base.OnInitializedAsync();
vm.Saved += NavigateToReturnUrl;
vm.ModelPropertyChanged += async (s, e) => await InvokeAsync(() => StateHasChanged());
} I know that the binding to my view model is working because when I'm performing the save, it is updating my BO with the value selected from the dropdown component. I also know that the ModePropertyChanged is working for the TextInput components that I have on the page. However, I have a business rule setup that checks the value selected and will generate a warning for certain values in the list of items. I know that the rule is working, because when I first enter the edit page, and the value for the field in my BO is one of those warning values, it is displayed in the DIV with the WarningText. But if I then select a different value from the dropdown that doesn't trigger the warning, I would expect the WarningText to disappear, and that isn't happening. And vice versa, if I go from a selected value without a warning to one that should have a warning, the WarningText is not displayed. BTW, this same issue occurs if I were to make the rule generate an error instead of a warning. So my question is, how do I fix this so that the warning is displayed or hidden when the value is changed? I assumed that the @Bind attribute would take care of all of that, and have even tried using @bind-value="Value" @bind-value:event="onchange" instead, but I get the same results. I'm not really sure how to troubleshoot this with the magic of @Bind and ModelPropertyChanged, so any insight or advice is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can put a breakpoint in your property setter (in the business class itself) to see if it is actually set (which it sounds like it is, but this would confirm). You can also set a breakpoint in the ModelPropertyChanged event handler, and examine the value of WarningText to see what it contains. |
Beta Was this translation helpful? Give feedback.
You can put a breakpoint in your property setter (in the business class itself) to see if it is actually set (which it sounds like it is, but this would confirm).
You can also set a breakpoint in the ModelPropertyChanged event handler, and examine the value of WarningText to see what it contains.