trying to create a very basic form with blazorstrap.
@page "/testform"
<h1> test form @Status</h1>
<EditForm Model=@Person OnSubmit=@FormSubmitted>
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label>
name:
<BSBasicInput T="string"
InputType="InputType.Text"
@bind-value=Person.Name />
</label>
</p>
<p>
<label>
Age:
<InputNumber @bind-Value="Person.Age" />
</label>
</p>
<p>
<label>
type:
<InputSelect @bind-Value="Person.Type">
<option value="">Select classification ...</option>
@foreach (var enumType in Enum.GetValues(typeof(BankAccountType)))
{
<option value="@enumType">@enumType</option>
}
</InputSelect>
@* <BSBasicInput T="BankAccountType?" InputType="InputType.Select" @bind-Value="Person.Type"> *@
@* <option value="">Select classification ...</option> *@
@* @foreach (var enumType in Enum.GetValues(typeof(BankAccountType))) *@
@* { *@
@* <option value="@enumType">@enumType</option> *@
@* } *@
@* </BSBasicInput> *@
</label>
</p>
<input type="submit" value="Submit" class="btn btn-primary" />
</EditForm>
@code
{
string Status = "Not submitted";
Person Person = new Person();
BankAccountType? AccountType = null;
void FormSubmitted()
{
Status = "Form submitted";
Console.WriteLine($"person: {Person} + " + AccountType);
}
private void SelectedChanged(BankAccountType? value)
{
Console.WriteLine("changed " + value);
}
}
the person class is
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public BankAccountType? Type { get; set; }
public override string ToString()
{
var accountType = Type.HasValue ? Type.Value.ToString() : "";
return $"{Name} is {Age} years old {accountType}";
}
}
The name binding with BSBasicInput works fine. using InputSelect for the select works fine. but when I try and use BSBasicInput with the InputType.Select (see commented out part). I cannot get it to bind, or at least show it is ever changing or setting either Person.Type or when I directly create a property in the razor file for it.
Sure I must be doing something wrong here, and its not blazorstrap, but can't see what it is now