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

Forums / Developing with Sitefinity / Adding custom field to Libraries

Adding custom field to Libraries

15 posts, 1 answered
  1. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    05 Jan 2011
    Link to this post
    Hi,

    I am needing to add a custom date field for my Libraries.

    I added the following line in my web.config:
    <!-- BEGIN Custom date field added by Keith -->
    <add key="Libraries.Publication_Date" valueType="DateTime" visible="True" searchable="True" sortable="True" defaultValue="#Now"/>
    <!-- END Custom date field added by Keith -->

    I also added the following lines to my ControlsConfig.xml:
    <viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemEdit" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemEdit.ascx" />
    <viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemPreview" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemPreview.ascx" />
    <viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemUpload`1[[Telerik.Libraries.WebControls.Admin.LibraryItemsView, Telerik.Libraries]]" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemUpload.ascx" />
    <viewSettings hostType="Telerik.Libraries.WebControls.Admin.LibraryItemList" layoutTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemList.ascx" />
    so that Sitefinity would use my custom templates.

    I modified LibraryItemList.ascx successfully so that the new field shows up in the overview of a library.

    Here is the problem though:
    I modified LibraryItemEdit.ascx by adding this block of code:
    <li>
      <asp:Label ID="Label11" runat="server" AssociatedControlID="Publication_Date" Text="Publication Date">
      </asp:Label>
      <telerik:RadDateTimePicker ID="Publication_Date" runat="server" ToolTip="Date">
      </telerik:RadDateTimePicker>
    </li>
    This was added in the same section as the Author and Description fields, and it shows up as expected when I click "edit" on a library item.  However, when I select and set a date then click save, it does not save anything to my new field.  Is there something else I need to add to get it to properly save the date to this field?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Jan 2011
    Link to this post
    Hi Keith,

    1. The RadDateTimePicker should be added inside the default ContentMetaFields control which shouldbe available in your template

    2. You should add the metakey inside <libraryInfo> element for the library you want to use.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    06 Jan 2011
    Link to this post
    um, that's what I did.

    Original block of code:
    <sfGCn:ContentMetaFields ID="itemMetaFields" runat="server">
                        <ItemTemplate>
                            <h3>
                                <asp:Literal ID="Literal11" runat="server" Text="<%$Resources:ItemEdit_Details %>"></asp:Literal></h3>
                            <fieldset class="set">
                                <ol class="setIn">
                                    <li>
                                        <asp:Label ID="Label7" AssociatedControlID="Author" runat="server" Text="<%$Resources:ItemEdit_Author %>"></asp:Label>
                                        <asp:TextBox runat="server" ID="Author"></asp:TextBox>
                                    </li>
                                    <li>
                                        <asp:Label ID="Label5" runat="server" AssociatedControlID="Description" Text="<%$Resources:ItemEdit_DocumentDescription %>"></asp:Label>
                                        <asp:TextBox runat="server" ID="Description" TextMode="MultiLine"></asp:TextBox>
                                    </li>
                                    <%-- BEGIN This is the code that I added: --%>
                                    <li>
                                        <asp:Label ID="Label11" runat="server" AssociatedControlID="Publication_Date" Text="Publication Date"></asp:Label>
                                        <telerik:RadDateTimePicker ID="Publication_Date" runat="server" ToolTip="Date"></telerik:RadDateTimePicker>
                                    </li>
                                    <%-- END --%>
  4. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    06 Jan 2011
    Link to this post
    no love for my question?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Jan 2011
    Link to this post
    Hello Keith,

    Have you added the key inside <libraryInfo> node in the web.config ?

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    06 Jan 2011
    Link to this post
    Hi Ivan,
    The key resides within the <libraryinfo> node.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Jan 2011
    Link to this post
    Hello Keith,

    OK. Here is the reason for this behavior. ContentMetaFields control supports the following types

    • ICheckBoxControl
    • ITextControl
    • RadDateInput
    • RadDatePicker
    In your case the ContentMetaFields cannot persist the data automatically. You should have a control that implements ITextControl if you want to persist your data using ContentMetaFields

    Take a look at this posts which provides a sample

    How to implement a drop down list or a radio button list as a meta field

    Another option is using RadDatePicker or TextBox, but if you use TextBox you should type the date manually or use a third party plug in that allows you to choose a date time value( jQuery UI Time Picker)
    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    17 Jan 2011
    Link to this post
    Hello Ivan,

    Thank you very much for the pointers.  I changed the input control to RadDatePicker and now it works properly.
    I do however have a new problem now.
    In my LibraryItemList.ascx the field value never shows.  The Publication Date column shows up but it just shows "undefined" even though I have verified that the values are being stored properly.

    The lines I added were:
    <telerik:ClientTemplate Name="Author" runat="server">{#MetaFields.Publication_Date#}</telerik:ClientTemplate>

    and further down I also added:
    <telerik:GridTemplateColumn UniqueName="Publication_Date" SortExpression="Publication_Date" HeaderText="Publication Date"></telerik:GridTemplateColumn>

    each under their appropriate sections.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Jan 2011
    Link to this post
    Hello Keith,

    You have to extend the js of the template

    function DataBindGrid(currentPageIndex, pageSize, sortExpressionsAsSQL, filterExpressionsAsSQL) {
        selectedContentIDs = [];
        var requiredMetaFields = ['Name', 'Extension', 'Permalink', 'Publication_Date'];
        var cultureInfoField = document.getElementById('<%= cultureInfoField.ClientID %>');
        Telerik.Cms.Engine.Services.ContentService.GetContentItems(currentPageIndex * pageSize, pageSize,
        sortExpressionsAsSQL, filterExpressionsAsSQL, requiredMetaFields, cultureInfoField.value, dataProviderName, updateGrid, OnFailed);
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  10. Keith
    Keith avatar
    67 posts
    Registered:
    13 Sep 2010
    17 Jan 2011
    Link to this post
    That did the trick - thanks!
  11. Big
    Big avatar
    8 posts
    Registered:
    14 Dec 2010
    05 Mar 2011
    Link to this post
    I want to do the same thing as this post, add a publication_Date to a library item.  I can't find the default files for all the custom templates like, LibraryItemPreview.ascx and 
       LibraryItemEdit.ascx

     where can I find these files? 
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Mar 2011
    Link to this post
    Hi ,

    They are embedded resources. Please take a look at How to map a template

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  13. Big
    Big avatar
    8 posts
    Registered:
    14 Dec 2010
    07 Mar 2011
    Link to this post
    I'm looking for this file,
    Sitefinity_3_7_1927_[standard]/[community]_ExternalTemplates.zip

    Do I not have access to it through my account?  Is there a direct link?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Mar 2011
    Link to this post
    Hi ,

    Please check the following link ( for your account)

    http://www.sitefinity.com/account/your-products/trial-product-versions/trial-single-download.aspx?pmvid=2288&pid=463

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  15. Big
    Big avatar
    8 posts
    Registered:
    14 Dec 2010
    07 Mar 2011
    Link to this post
    Thanks Ivan!
Register for webinar
15 posts, 1 answered