This is a migrated thread and some comments may be shown as answers.

Label Field control

4 Answers 687 Views
Form
This is a migrated thread and some comments may be shown as answers.
Frans
Top achievements
Rank 1
Veteran
Iron
Frans asked on 16 Mar 2021, 09:42 AM

Hi,

How can I get a label field in the Form ? 

Is it supported out of the box ? Or should I use a span for this ? Or a custom template ?

Martin

 

4 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 19 Mar 2021, 07:59 AM

Hi Frans,

You could use the items.label option to define the label of the field. You could find an example in the Demo linked here.

If you inspect the text before each item you will see that a <label/> element is rendered. Here is a screencast where you could see the label element rendered for the Password field in the Basic usage Form Demo. 

I hope the provided information will be helpful.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Frans
Top achievements
Rank 1
Veteran
Iron
answered on 20 Apr 2021, 06:59 AM

Hi Neli,

 

I understand. But this is a clientside solution.

I want this supported serverside in a easy way like for all the other control items. Something like ....Label("MyLabel");

best regards,

Martin

0
Neli
Telerik team
answered on 23 Apr 2021, 05:10 AM

Hi Frans,

Please excuse me in the last reply I sent you a link to the jQuery Demos. Here you will find a link to the UI for ASP.NET MVC demos. Below you will find an example of how the label could be configured when using the server-side wrappers:

 i.Add()
       .Field(f => f.FirstName)
       .Label(l => l.Text("First Name:"));

 If you need to use a value from the model, you can pass it as in the example below:

.Label(l => l.Text(@Model.FirstName));

I would also encourage you to cast a vote for the Feature request linked below for adding support for text of the labels in the Form to be retrieved from DataAnnotations:

https://feedback.telerik.com/aspnet-core-ui/1508987-add-support-for-text-of-the-labels-in-the-form-to-be-retrieved-from-dataannotations

Let me know in case you have additional questions on the matter. 

Regards,
Neli
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

0
Frans
Top achievements
Rank 1
Veteran
Iron
answered on 26 Apr 2021, 02:56 PM

Thanks Neli,

I upvoted the feature request, I think it is so basic it should just be there.

 

The solution above is not a solution for me, so I tried to make a quick hack for this problem:

 // Render a textbox, and style it as a label (will be posted to server)

                        items.Add()
                            .Field(propInfo.Name)
                            .Label(propInfo.Label)
                            .EditorTemplate($"<input id=\"{propInfo.Name}\" name=\"{propInfo.Name}\" type=\"text\"  style=\"border: 0px;background:transparent;caret-color: transparent;outline:none;padding:5 0 0 0;\"  readonly   /> ");

Of course its better to put the css not inline, but this is just to demonstrate.

Neli
Telerik team
commented on 29 Apr 2021, 10:59 AM

Hi Frans, 

Thank you very much for sharing the solution that is suitable for your scenario with the community. I am sure it will be helpful to the other users in the Forum. 

Thank you also for voting for the Feature request. We will keep monitoring the demand and depending on the votes the issue collects we might consider the implementation of the requested functionality in the future.

Tags
Form
Asked by
Frans
Top achievements
Rank 1
Veteran
Iron
Answers by
Neli
Telerik team
Frans
Top achievements
Rank 1
Veteran
Iron
Share this question
or