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

Is the Field attribute of FormItem needed?

1 Answer 600 Views
Form
This is a migrated thread and some comments may be shown as answers.
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
Marc Simkin asked on 21 Apr 2021, 06:43 PM

If I am using templates for all my FieldItems, does each FieldItem need to have the Field attribute to associate the fielditem with the corresponding field in the data model?

See the sample markup below.

Thanks

<TelerikForm EditContext="@EditContext"
             Columns="2"
             ColumnSpacing="20px"
             Orientation="FormOrientation.Vertical"
             OnValidSubmit="OnValidSubmit">
    <FormValidation>
        <FluentValidationValidator />
    </FormValidation>
    <FormItems>
        <FormGroup LabelText="Set options">
            <FormItem>
                <Template>
                    <label class="k-label k-form-label" for="setName">Set Name</label>
                    <TelerikTextBox Id="setName" @bind-Value="@model.SetName"></TelerikTextBox>
                </Template>
            </FormItem>
            <FormItem>
                <Template>
                    <TelerikDateRangePicker @bind-StartValue="@model.StartDate"
                                            @bind-EndValue="@model.EndDate"
                                            Min="@ViewModel.MinStartDate"
                                            StartId="startDate"
                                            EndId="endDate"
                                            DisabledDates="@ViewModel.DisabledDates">
                    </TelerikDateRangePicker>
                </Template>
            </FormItem>
            <FormGroup Columns="2">
                <FormItem>
                    <Template>
                        <label class="k-label k-form-label" for="allowAutoFill">Allow Auto Fill</label>
                        <TelerikCheckBox Id="allowAutoFill" @bind-Value="@model.AllowAutoFill"></TelerikCheckBox>
                    </Template>
                </FormItem>
                <FormItem Field="@nameof(model.RequiredRecsToExpire)">
                    <Template>
                        <label class="k-label k-form-label">Required Recs to Expire</label>
                        <TelerikSlider @bind-Value="@model.RequiredRecsToExpire"
                                       Min="0"
                                       Max="20"
                                       SmallStep="1"
                                       LargeStep="5"
                                       ShowButtons="false" />
                    </Template>
                </FormItem>
            </FormGroup>
        </FormGroup>
        <FormGroup LabelText="Initial starting point">
            <FormItem LabelText="existingSets">
                <Template>
                    <label class="k-label k-form-label" for="existingSets">From existing recommendation sets</label>
                    <RecSetSelector AvailableSets="@ViewModel.AvailableSets"
                                    IsNew="true"
                                    SelectedSetId="@ViewModel.SelectedSetId"
                                    OnSetSelected="@OnSetSelected" />
                </Template>
            </FormItem>
            <FormItem>
                <Template>
                    <label class="k-label k-form-label" for="eanList">From a list of EANs</label>
                    <TelerikTextArea Id="eanList"
                                     @bind-Value="@ViewModel.EanList"
                                     AutoSize="true">
                    </TelerikTextArea>
                </Template>
            </FormItem>
        </FormGroup>
        <FormItem ColSpan="2">
            <Template>
                @*<br />*@
                <label class="k-label k-form-label" for="comment">Comments</label>
                <TelerikTextArea Id="comment"
                                 @bind-Value="@model.Comment"
                                 AutoSize="true">
 
                </TelerikTextArea>
            </Template>
        </FormItem>
        <ValidationSummary />
    </FormItems>
    <FormButtons>
        <TelerikButton ButtonType="ButtonType.Button" OnClick="OnCancel">Cancel</TelerikButton>
        <TelerikButton ButtonType="ButtonType.Submit" Primary="true">Save</TelerikButton>
    </FormButtons>
</TelerikForm>

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 23 Apr 2021, 07:08 AM

Hi Marc,

The Field of the FormItem is only necessary if you will be using the built-in editor it will generate, so it can know what to do. If you will be using the Template to @bind your own editor, you don't have to set the Field parameter of the FormItem. 

I have also added this bit of info to the docs (commit link, to be live with our next upload).

Regards,
Marin Bratanov
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/.

Tags
Form
Asked by
Marc Simkin
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Marin Bratanov
Telerik team
Share this question
or