Required attribute does not appear

Followed instructions from this thread https://www.syncfusion.com/forums/172106/is-there-any-way-to-make-sftextbox-to-do-client-side-validation-for-required-attribute


I do not have the a required attribute on that property of the C# class, but that shouldn't matter.



        <SfDropDownList CssClass="mb-3" HtmlAttributes="@(new Dictionary<string,object>() { { "required", "true" } })"

                        TValue="string"

                        TItem="SyncFusionDropDownListItem"

                        @bind-Value="_viewModel.Cause"

                        DataSource="SyncFusionDropDownListFactory.GetCauses()"

                        Placeholder="Select Country"

                        AllowFiltering="true">

            <DropDownListFieldSettings Text="DisplayText" Value="Value"></DropDownListFieldSettings>

        </SfDropDownList>


3 Replies

SP Sureshkumar P Syncfusion Team June 30, 2022 07:56 AM UTC

Hi Jason,

We have validated the reported issue on our end, but we cannot replicate the reported issue on our end. Please find the code and screenshot below.

Find the code example here:

<SfDropDownList TValue="string[]" TItem="Country" HtmlAttributes="@(new Dictionary<string,object>() { { "required", "true" } })" DataSource="@Countries">

    <DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>

</SfDropDownList>

Find the screenshot here:

Regards,

Sureshkumar P



JA Jason June 30, 2022 09:29 PM UTC

Sorry, I was looking at the wrong element. Anyway, the reason I posted is that when you submit the form, the browser never prompts you about the missing field. All the InputText show the browser prompt to fill out a missing field except for the drop down list. I was able to submit the form without interacting with the dropdown list.


Here is what the browser UI shows when working correctly:




SP Sureshkumar P Syncfusion Team July 1, 2022 01:21 PM UTC

Hi Jason,

We suggest you refer to the below forum answer to achieve your requirement. In the below forum we have prepared the sample with dropdownlist client-side validation.

Forum link: http://www.syncfusion.com/forums/172516/client-side-validation-on-dropdown-list?reply=S239it

Regards,

Sureshkumar P


Loader.
Up arrow icon