FormAutoGeneratedItems - custom rendering?

1 Answer 235 Views
Form
Michael
Top achievements
Rank 1
Michael asked on 01 Jun 2023, 01:17 PM

Are there any examples or suggested methods of modifying the way FormAutoGeneratedItems renders?  I understand that I can do individual fields with templates - but for the most part we only need a minor tweak (add red * for required fields). 

 

There may be an obvious approach, but I don't yet see it - looking to see if anyone has done anything similar 

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 06 Jun 2023, 06:59 AM

Hi Michael,

You can add the * symbol in the Display Name data annotation attribute. Otherwise you will need explicit FormItem tags with a LabelText or Hint or Class parameter. Using custom CSS styles will allow you to set a color to the asterisk.

<TelerikForm Model="@PersonModel">
    <FormItems>
        <FormItem Field="@nameof(Person.FirstName)" LabelText="First Name" Class="required-field"></FormItem>
        <FormItem Field="@nameof(Person.LastName)" LabelText="Last Name" Class="required-field"></FormItem>
        <FormItem Field="@nameof(Person.DOB)" LabelText="Date of Birth" Hint="Not required..."></FormItem>
    </FormItems>
</TelerikForm>

<style>
    .required-field .k-form-label::after {
        content: "*";
        color: red;
        padding-left: .4em;
    }
</style>

@code {
    public Person PersonModel = new Person();

    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime DOB { get; set; }
    }
}

Regards,
Dimo
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Michael
Top achievements
Rank 1
commented on 06 Jun 2023, 01:22 PM

Thanks Dimo.

 

Just a wish list item, but if FormAutoGeneratedItems could recognize the [Required] attribute from the model and append the "required-field" class - that would be perfect.  I like use of the FormAutoGeneratedItems because it handles the display name, etc

For the time being, we will pivot to using individual form items

Tags
Form
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or