Multi Single Line List

  0 rating
6/17/2019 4:17:25 PM
6/19/2019 6:48:30 PM
Provider: Vikash Raaj

About

Normally Sitecore doesn’t support multiple Single line Text field, this is a major need when we need to maintain different values based on Author input. Majorly it plays a role on setting multiple values for a field based on Author decision.


We are required to use the multi list, or name value collection in order to maintain different values. If I want to hold multiple values without different key is not possible, but here the possibilities comes to play.


User can add any number of times same or different values to the same field, no restrictions.

Documentation

Documentation
  • Documentation > bSITECORE CUSTOM FIELD MULTI SINGLE LINE TEXTb
    <b>SITECORE CUSTOM FIELD MULTI SINGLE LINE TEXT</b>

    Why Multi Single Line Text field Custom Field

    Normally Sitecore doesn’t support multiple Single line Text field, this is a major need when we need to maintain different values based on Author input. Majorly it plays a role on setting multiple values for a field based on Author decision.

    We are required to use the multi list, or name value collection in order to maintain different values. If I want to hold multiple values without different key is not possible, but here the possibilities comes to play.

    User can add any number of times same or different values to the same field, no restrictions.

    How to use the Custom Field.

    Package Installation

    1st step is to install the package for the custom field that we built, Currently the Dll is built on Sitecore 9.1.1 version and it would support all lower versions also.

    Field Inclusion in Template

    Create new field in the template and select the field Multi Single-Line List Under Custom Fields.

    Field Value Read\Write in Sitecore

    Now create an item with the template that is created by using the Customer Field as one of the field. And go to that item.

    It would show the Field as a single line text box.

    On focusing on to the text box it automatically creates, additional text box similar to name value field type.

    Now type some data and save. 

    Field value Read\Write Via Code

    1. Add the dll to your solution. [Sitecore.Foundation.Field.MultiSingleLineListField.dll]
    2. Include namespaceà Sitecore.Foundation.Field.MultiSingleLineListField.CustomField
    3. Below piece of code will help to get the value as the List<string> from the custom field.

    var itemId = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}";

     

                var id = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(itemId));

                var key = "Custom Field";

              

                MultiSingleLineListField mm = id.Fields[key];

                var valuesFromfield = mm.SingleLineMultiListValues;

     above sample code can pull the value from the Sitecore as below.

    Updating the Field Value Via Code

    Below piece of code will help to update the field values on run time via programmatically.

    using (new SecurityDisabler())

                {

                    id.Editing.BeginEdit();

                    List<string> newInput = new List<string>() { "Vikash", "Modified ", "Content", "Via", "Code" };

                    MultiSingleLineListField modify = id.Fields[key];

                    modify.SingleLineMultiListValues = newInput;

                    id.Editing.EndEdit();

                }

    Check the Sitecore whether the Field value has been modified or not.

     

    Future Enhancements

                    Add the field to work in Experience editor mode too.

     

    0
Back
Release notes
Please insert section here whenever you add a new version of your Sitecore module package describing version number, new features, fixes and possible known issues.
Read more Back
Code examples
  • Code examples > bReadUpdate Field Valueb
    <b>Read\Update Field Value</b>

    Get Custom Field Value

    var itemId = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}";

     

                var id = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(itemId));

                var key = "Custom Field";

              

                MultiSingleLineListField mm = id.Fields[key];

                var valuesFromfield = mm.SingleLineMultiListValues;

    above sample code can pull the value from the Sitecore as below.

    Updating the Field Value Via Code

    Below piece of code will help to update the field values on run time via programmatically.

    using (new SecurityDisabler())

                {

                    id.Editing.BeginEdit();

                    List<string> newInput = new List<string>() { "Vikash", "Modified ", "Content", "Via", "Code" };

                    MultiSingleLineListField modify = id.Fields[key];

                    modify.SingleLineMultiListValues = newInput;

                    id.Editing.EndEdit();

                }

    Check the Sitecore whether the Field value has been modified or not.


    0

Solution screenshots(0)

Upload

Reviews (0)

Sort by: Date Most votes
  • Profile Avatar
    [fullName]

    Level: 0

    x0 x0 x0

    [date]

    [title]

    [text]

    Was this helpful?

    0

Comments (0)

Sort by: Date  Most votes

Leave a Comment

Comment must be field in
Post comment
loader

Write a review

Title can't be empty
Review can't be empty
Post review

Download

Title Description Download Action

Add File