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

Forums / Developing with Sitefinity / Problem Validating a Custom Metafield in Libraries Module

Problem Validating a Custom Metafield in Libraries Module

7 posts, 0 answered
  1. Erik
    Erik avatar
    34 posts
    Registered:
    06 Dec 2007
    08 Jan 2009
    Link to this post
    I'm trying to get a custom metafield to be a required field in the Images and Documents module.

    I got it working on the BatchEdit.ascx file by adding the RequiredFieldValidator and using an asp:textbox to store the info, which is called "PublishedDate" and the metafield is of type DateTime.

    It's for some reason not working when I add the same code to display the input field on the ControlPanelEdit.ascx page.  I noticed that when I upload a document or edit an existing document that has no "PublishedDate" filled in, that it automatically plops in the date "1/1/0001 12:00:00 AM".  It doesn't do this on the BatchEdit screen, only on the ControlPanelEdit screen even though the code is exactly the same on both.  Here it is for reference:

    <asp:Label ID="lblDatePublished" runat="server" AssociatedControlID="PublishedDate" Text="Date Published" </asp:Label>
    <asp:TextBox ID="PublishedDate" runat="server" />
    <asp:RequiredFieldValidator ID="rfvPublishedDate" runat="server" ControlToValidate="PublishedDate" ValidationGroup="editGroup" CssClass="validMessage" Display="Dynamic" EnableViewState="False" SetFocusOnError="true"><strong><asp:Literal ID="Literal22" runat="server" Text="<%$Resources:PublishedDateEmpty %>"></asp:Literal></strong></asp:RequiredFieldValidator>

    This code is literally verbatim between the BatchEdit.ascx and the ControlPanelEdit.ascx yet when I try to edit a single document, the validator fails to validate and it sticks in that dummy date that won't save.  Not only do I need it to display a blank field on load (which it does do in the BatchEdit screen for any document with a blank PublishedDate) but I need the validator to work when they try to save the file and also save the inputted date following the validation.

    Also, why doesn't the date "1/1/0001" actually save in the database even though it is not a valid date?  I mean technically this field is filled in with that text and it doesn't save for some reason, why not?

    Thanks for your help on this and please let me know how I can get that default date text to go away completely.

    Erik

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    10 Jan 2009
    Link to this post
    Hello Erik,

    The described problem with the DateTime meta fields in Images & Documents is a known issue and will be fixed for the upcoming release.

    Regarding the controlpanel validation, try to set ValidationGroup property of the RequiredFieldValidator to editItem:

    <asp:Label ID="lblDatePublished" runat="server" AssociatedControlID="PublishedDate" Text="Date Published"></asp:Label> 
    <asp:TextBox ID="PublishedDate" runat="server" /> 
    <asp:RequiredFieldValidator ID="rfvPublishedDate" runat="server" ControlToValidate="PublishedDate" ValidationGroup="editItem" CssClass="validMessage" Display="Dynamic" EnableViewState="False" SetFocusOnError="true"><strong><asp:Literal ID="Literal22" runat="server" Text="<%$Resources:PublishedDateEmpty %>"></asp:Literal></strong></asp:RequiredFieldValidator>  

    Note that ValidationGroup of the validator and the save button should be the same.

    Hope this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Erik
    Erik avatar
    34 posts
    Registered:
    06 Dec 2007
    16 Jan 2009
    Link to this post
    Excellent!  Thank you for the help.  Might I ask as well, what does that setting actually do?  Just changing it from "editGroup" to "editItem" made it work, but how and what does the setting mean?

    Thanks a bunch!
    Erik
  4. Erik
    Erik avatar
    34 posts
    Registered:
    06 Dec 2007
    16 Jan 2009
    Link to this post
    Actually, looks like I spoke a little too soon.  I just tested it and while the validation actually works now, the document that I upload is still getting saved to the Library even when I click "Cancel".  This obviously should not happen, so could you tell me how to fix that?
  5. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Jan 2009
    Link to this post
    Hi Erik,

    Actually, this behavior is by design.
    The problem is that the image is uploaded a step before the meta field screen appears. Having that said, the image is indeed already there. Perhaps you should change your approach for this task. I am going to raise a question about the usability here, and possibly we will change this in some of our future versions.

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Erik
    Erik avatar
    34 posts
    Registered:
    06 Dec 2007
    21 Jan 2009
    Link to this post
    Yeah, you should raise the question of usability, cause frankly it seems that the logical outcome of clicking the 'cancel' button should basically undo the entire upload operation of the document, which it currently does not do. 

    If I am to train other users how to upload documents that require my custom fields to be filled in and they mistakenly upload an incorrect document and need to cancel the operation, this will cause confusion when the document they intended to cancel still shows up.  Also, because of a bug in your documents module, not having this field filled in causes entire pages to break because apparently when adding custom metafields to documents and then placing validations on them requires each document to have a value for that field in it or else it throws an "object reference not set to an instance of object" error.

    This is why I have to use validation to require this field be filled in, because if just one document in the library doesn't contain a value for the custom field, the entire page fails to load.
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    23 Jan 2009
    Link to this post
    Hi Erik,

    I completely agree with everything said. I followed up this conversation to the people involved with the usability.

    Kind regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered