chanan / BlazorStrap

Bootstrap 4 Components for Blazor Framework
https://blazorstrap.io
The Unlicense
910 stars 156 forks source link

how validate a select option #567

Closed AmBplus closed 1 year ago

AmBplus commented 1 year ago

i have a form and inside of it i want get year as select option , and validate the year is valid or not ! bellow code is the select option i created

<div class="mb-3">
    <BSLabel>Select Year</BSLabel>
    <BSInput CheckedValue="true"
       ValidateOnChange="true" InputType="InputType.Select" 
       @bind-Value="dateTitle.selectedYear" >
         @{
           <option >@("Select Year")</option>
           foreach(var year in GetYear())
           {
            <option value="@(year)">@(year)</option>
           }
          }
    </BSInput>
<BSFeedback For="@(() => dateTitle.selectedYear)" 
InvalidMessage="select year is nessary" />
</div>

but there is no validation happen for year

bellow code is the logic

   [Required(ErrorMessage ="select year is nessary")]
        [Range(minimum:  1390, maximum:  1450)]
        public int? selectedYear;
jbomhold3 commented 1 year ago

Hi, Two things I can't see by the example you provided are the BSForm tag and <DataAnnotationsValidator /> tag. Provided they are there do the following to troubleshoot.

The form controls are just formatted wrappers for the Blazor Default built-in input components controls. Use <InputSelect @bind-Value="starship.Classification"> and see if it works as expected. If the issue persists we might have to log an issue directly on the AspNetCore repo. If it does fix your issue let me know and can investigate further.