Developer forum

Forum » CMS - Standard features » Required attributte from itemtype field

Required attributte from itemtype field

Lars Larsen
Reply

Hi

Using Razor in my template I am looping throug the loop "ItemCreator:Edit.Item.Groups" and in that I am looping throug the loop "ItemCreator:Edit.Item.Group.Fields". In the fields loop I would very much like to get the required attributte for an itemtype field. This because I want to render a red star after the field label if the field is mandatory. But I can't see a required tag value! Here is my code:

            @foreach (var group in GetLoop("ItemCreator:Edit.Item.Groups"))
            {
                <div class="item-edit-fields">
                    <div class="item-edit-field-group">
                        <div class="item-edit-field-group-name">@group.GetValue("ItemCreator:Edit.Item.Group.Name")</div>
                        <div class="item-edit-field-group-content ">
                            @foreach (var field in group.GetLoop("ItemCreator:Edit.Item.Group.Fields"))
                            {
                                <div class="item-edit-field items-clear">
                                    <label class="item-edit-field-label">@field.GetValue("ItemCreator:Edit.Item.Field.Name") <span class="required">*</span></label>
                                    <div class="item-edit-field-value">
                                        @if (field.GetString("ItemCreator:Edit.Item.Field.EditorType").Contains("Dynamicweb.Content.Items.Editors.FileEditor"))
                                        {
                                            <input type='file' name='@field.GetValue("ItemCreator:Edit.Item.Field.SystemName")' accept='@field.GetValue("ItemCreator:Edit.Item.Field.Extensions")' />
                                        }
                                        else
                                        {
                                            @field.GetValue("ItemCreator:Edit.Item.Field.Control")
                                        }
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                </div>
            }


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

Just a few days ago, I added exactly that to our development branch of Dynamicweb. When we make a release with that feature you can write something like

<div class='item-edit-field items-clear @(field.GetBoolean("ItemCreator:Edit.Item.Field.IsRequired") ? "required" : "")'>

to mark the field as required.

Best regards,
Mikkel

Votes for this answer: 1
 
Lars Larsen
Reply

You're my man Mikkel smiley

 

You must be logged in to post in the forum