+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Fields - Content Blocks

Custom Fields - Content Blocks

4 posts, 0 answered
  1. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    04 Jul 2012
    Link to this post
    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?
  2. Grace Hallwachs
    Grace Hallwachs avatar
    144 posts
    Registered:
    03 Nov 2014
    06 Jul 2012
    Link to this post
    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
  3. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    01 Aug 2013 in reply to Grace Hallwachs
    Link to this post
    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.
  4. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    05 Dec 2016
    05 Aug 2013
    Link to this post
    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
4 posts, 0 answered