SITECORE CUSTOM FIELD MULTI SINGLE LINE TEXT
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
-
Add the dll to your solution. [Sitecore.Foundation.Field.MultiSingleLineListField.dll]
-
Include namespace Sitecore.Foundation.Field.MultiSingleLineListField.CustomField
-
Below piece of code will help to get the value as the List 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 newInput = new List() { "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.
-
Sitecore Marketplace Update Plugin has been added to Sitecore marketplace and its under evaluation