How to hide label in form

1 Answer 1250 Views
Form Switch
Humberto
Top achievements
Rank 1
Iron
Humberto asked on 14 Feb 2022, 06:31 PM

Hi, I'm new to Telerik ASP.NET Core, so maybe this is a simple task. I'm using Razor Pages and would like to hide the label from one field, how can this be done? From the switch field.

Thanks,

Humberto

                    @(Html.Kendo().Form<ProfileModel>()
                            .Name("formExample")
                            .FormData(Model?.Input)
                            .HtmlAttributes(new { method = "POST" })
                            .Layout("grid")
                            .Grid(g => g.Cols(1).Gutter(0))
                            .Items(items => {
                                items.AddGroup()
                                    .Label("Security")
                                    .Layout("grid")
                                    .Grid(g => g.Cols(2))
                                    .Items(i =>
                                    { 
                                        i.Add()
                                            .Field(f=> f.TFA)
                                            .Editor(e => e.Switch());
                                });

                            })
                            .Validatable(v =>
                            {
                                v.ValidateOnBlur(false);
                                v.ValidationSummary(false);
                                v.ErrorTemplate("<span style='color: red'>#:message#</span>");
                            })
                    )                

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar
Telerik team
answered on 15 Feb 2022, 09:38 AM

Hi Humberto,

To hide the label of a given From field, you can use the below configuration. This REPL example demonstrates the usage of the below code. 

i.Add()
    .Field(f => f.Feedback)
    .Label(l => l.Text(" "))
    .Editor(e => e.Switch());

I hope the suggested above approach will help you achieve what you need in your application. 

Regards,
Petar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Humberto
Top achievements
Rank 1
Iron
commented on 15 Feb 2022, 12:00 PM

It works, but it's not very intuitive; Just for the records, IMHO it would be cleaner if it was something like:

i.Add()
    .Field(f => f.Feedback)
    .Label(l => l.Hidden())
    .Editor(e => e.Switch());

Thanks,

Humberto

Petar
Telerik team
commented on 15 Feb 2022, 04:19 PM

Hi, Humberto.

Thank you for the suggestion. We will consider it and may introduce improvements in the Form configuration. 

Tags
Form Switch
Asked by
Humberto
Top achievements
Rank 1
Iron
Answers by
Petar
Telerik team
Share this question
or