Reputation: 29159
(Tried both in Visaul Studio 2019 V16.4.0 or V16.4.1. Microsoft.CodeAnalysis.FxCopAnalyzers added)
I'm using the following code in Blazor to disable inputs.
<input type="checkbox" @bind="@v" disabled="@(!isEditing || ...expression omitted...)" />
However, Visual Studio warns that
Warning '@(!isEditing || ...)' is not a valid value of attribute 'disabled'
What's the proper way to disable the input by custom logic?
Upvotes: 0
Views: 2793
Reputation: 29159
It's a bug.
HTML warning when setting disabled attribute using Razor syntax #16833 https://github.com/aspnet/AspNetCore/issues/16833
Update:
All the warnings are disappeared after my Visual Studio is upgraded to V16.4.2.
Upvotes: 2
Reputation: 579
Use a ternary expression:
<input type="checkbox" @bind="@v" @((!isEditing || ...expression omitted...) ? "disabled" : "") />
Upvotes: 0
Reputation: 17404
html disabled
attribute acceptable value is disabled or no value.
The easiest way is to use an @if statement:
@if(!isEditing || ...omitted...)
{
<input type="checkbox" @bind="@v" disabled />
}
else
{
<input type="checkbox" @bind="@v" />
}
Upvotes: 0