Reputation: 976
I am trying to build a InputText for Blazor which holds a placeholder if the skill is yet null so is created as a new one, since I want to use the same razor component for edit and create new skill:
<div class="form-group">
<label>Skillname</label>
@if (Skill == null)
{
<InputText class="form-control" placeholder="Enter Skillname" @bind-Value="Skill.Name"/>
}
else
{
<InputText @bind-Value="Skill.Name" class="form-control"/>
}
</div>
I tried to set placeholder=".."
without having any effect. After research I found that they were using placeholder
here even though it is not working for me.
I only found this possibility with telerik front end framework.
I was not able to find any reference to placeholder in the documentation.
Andy idea why placeholder
is not working here or if there is any other workaround to achieve this?
Upvotes: 7
Views: 10816
Reputation: 467
There is no intellisense and that is what confuses people. However, if you just use the placeholder attribute it will work.
<InputText id="lastName" class="form-control" placeholder="Last Name" @bind-Value="EmployeeVM.LastName"></InputText>
Upvotes: 14
Reputation: 30074
You're binding to @bind-Value="Skill.Name"
so I'm assuming Skill
isn't null. Your test is on skill
, not skill.Name
, so is never null
you always hit the else
option. Try:
@if (string.IsNullOrEmpty(skill.Name))
{
......
}
And you get:
However, you don't need to do any of this as the placeholder will only display when the field is empty.
Upvotes: 4