Custom Fields - Content Blocks

Posted by Community Admin on 04-Aug-2018 12:13

Custom Fields - Content Blocks

All Replies

Posted by Community Admin on 04-Jul-2012 00:00

Hi Team Telerik,

I need to create a custom fields for generic content. Please let me know, how can I do this?

I have created those for news module, but how can I create it for Content Blocks?

Posted by Community Admin on 06-Jul-2012 00:00

Hello,

Thank you for contacting us.

The Content Blocks, which we are using in Sitefinity 5.0 are not a dynamic content, so it is not possible to add custom fields in this type of content through the UI.

There are a few workarounds:

1) The easiest would be to create dynamic module with the module builder so you can get more fields in the User interface, however they will no be shared content. 

2) This workaround is more complex I would suggest using the first workaround if possible. You may want to add them through the configuration files. Each new custom field composes of the opening element <field> to </field>.  To add new custom fields you will have to add them in the news module for example. Take the generated XML and paste it in your
ContentConfig.contentViewControls.ContentBackend.views.ContentBackendEdit.config file.

<fields>
                <field rows="1" dataFieldName="pageSelector" wrapperTag="Li" title="pageSelector" fieldType="PageSelector.PageSelectorField" fieldName="pageSelector" type:this="PageSelector.PageSelectorFieldElement, PageSelector">
                    <expandableDefinition expanded="True" />
                    <validator expectedFormat="None" maxLength="0" minLength="0" alphaNumericViolationMessage="Non alphanumeric characters are not allowed." currencyViolationMessage="You have entered an invalid currency." emailAddressViolationMessage="You have entered an invalid email address." integerViolationMessage="You have entered an invalid integer." interneturlviolationmessage="You have entered an invalid URL." maxLengthViolationMessage="Too long" maxValueViolationMessage="Too big" messageCssClass="sfError" messageTagName="div" minLengthViolationMessage="Too short." minValueViolationMessage="Too small." nonAlphaNumericViolationMessage="Alphanumeric characters are not allowed." numericViolationMessage="You have entered an invalid number." percentageViolationMessage="You have entered an invalid percentage." regularExpressionViolationMessage="Invalid format" requiredViolationMessage="Required field." usSocialSecurityNumberViolationMessage="You have entered an invalid US social security number." usZipCodeViolationMessage="You have entered an invalid US ZIP code." validateIfInvisible="True" />
                </field>
            </fields>

You will have to use the API to manually add persistence of the new custom field.

App.WorkWith()
               .DynamicData()
               .Type(typeof(Telerik.Sitefinity.GenericContent.Model.ContentItem))
               .Field().TryCreateNew("Best", typeof(string))
               .SaveChanges();

in my case "Best" is the name of the custom field added.

The problem comes form the fact this field is created dynamically. You should create the field programmatically using DynamicData facade so the associated methods calls in the facade are executed.

If you need any further assistance, feel free to write back.

Greetings, Grace Hallwachs
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-Aug-2013 00:00

I am quite keen on actually doing this. The benefit of allowing the user to tag the content is quite important therefore I will need to follow up this solution.
@Siddesh did you implement this? And if so, can you share more info on it?
@Grace Hallwachs, do you have an example of this. Also, should one assume that you only have to create that field once? What do you mean by persistency? Do you have an example where this is done with categories?

Many thanks in advance.

Posted by Community Admin on 05-Aug-2013 00:00

Hello,

@Ricardo
It seems that Grace's suggestions are the only available workaround at this moment. This functionality is not offered in 6.1 of Sitefinity as well, so I would suggest to try the available workaround.

Regards,
Kaloyan
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed