Unplanned
Last Updated: 14 Aug 2023 07:53 by ADMIN
Doug
Created on: 16 Aug 2022 14:15
Category: Form
Type: Feature Request
10
Add the ability to define form columns with different widths

Currently, you can split the TelerikForm into multiple columns via the Columns parameter. These columns will have equal widths. I would like to have the ability to define custom width per column. 

<AdminEdit>

You can use the following code snippet as a workaround with some considerations:

  • The k-grid-cols-2 class is a dynamic one. The "2" segment maps to the number of the columns defined via the Columns parameter exposed for the <TelerikForm>
  • If there are more/less than two columns, you should change the values for the grid-template-columns accordingly.

<style>
    .non-equal-columns .k-form-layout.k-grid-cols-2 {
        grid-template-columns: 71% 28.5%;
    }
</style>

@using System.ComponentModel.DataAnnotations

<TelerikForm Model="@person" ColumnSpacing="25px" Columns="2" Class="non-equal-columns">
    <FormValidation>
        <DataAnnotationsValidator></DataAnnotationsValidator>
    </FormValidation>
    <FormItems>
        <FormGroup LabelText="Personal Information" ColumnSpacing="15px">
            <FormItem LabelText="First Name" Field="@nameof(Person.FirstName)"></FormItem>
            <FormItem LabelText="Last Name" Field="@nameof(Person.LastName)"></FormItem>
            <FormItem LabelText="Age" Field="@nameof(Person.Age)"></FormItem>
            <FormItem LabelText="Email" Field="@nameof(Person.Email)"></FormItem>
        </FormGroup>
        <FormGroup LabelText="Employee Information" Columns="2" ColumnSpacing="15px">
            <FormItem LabelText="Company Name" Field="@nameof(Person.CompanyName)"></FormItem>
            <FormItem LabelText="Position" Field="@nameof(Person.Position)"></FormItem>
        </FormGroup>
    </FormItems>
</TelerikForm>

@code {
    public Person person { get; set; } = new Person();

    public class Person
    {
        [Required(ErrorMessage = "The First name is required")]
        public string FirstName { get; set; }
        [Required(ErrorMessage = "The Last name is required")]
        public string LastName { get; set; }
        [Range(18, 120, ErrorMessage = "The age should be between 18 and 120")]
        public int Age { get; set; }
        [Required]
        [EmailAddress(ErrorMessage = "Enter a valid email")]
        public string Email { get; set; }
        [Required]
        public string CompanyName { get; set; }
        [MaxLength(25, ErrorMessage = "The position can be maximum 25 characters long")]
        public string Position { get; set; }
    }
}

</AdminEdit>

0 comments