BUG - Auto-update DateTime fields not working?

2 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 06 Dec 2012 Link to this post

    Hello,

    I found this post from last year asking about the use of datetime fields, and your response mentioned that the auto-update feature wasn't implemented.
    http://www.telerik.com/community/forums/silverlight/richtextbox/date-amp-time-and-table-resizing.aspx

    As of v2012.3.1023.1050, there is in fact an "Update Automatically" feature on the insert date time dialog...  But it doesn't look like it's working when we save and re-open documents.  It is supposed to be?

    Thanks,
    Rob 

  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 11 Dec 2012 Link to this post

    Hi Rob,
    When you insert a date and select the Update Automatically option, a DateField is inserted in the document, as opposed to a simple span with DateTime.Now in it when you do not select that option. However, fields are not updated automatically when you export and import back the document. They can be updated manually through the context menu option UpdateFiled or by calling one of the methods of the editor.
    What you can do in order to work around this issue is to subscribe to the DocumentChanged event of the editor and update either all fields in the document - note that this should be slower:
    void editor_DocumentChanged(object sender, EventArgs e)
    {
        (sender as RadRichTextBox).UpdateAllFields(FieldDisplayMode.Result);
    }
    or if you do not want to do that (if you have other types of fields that should not be updated at this point for example), you can enumerate only the DateFields and update them:
    void editor_DocumentChanged(object sender, EventArgs e)
    {
        List<FieldRangeStart> dates = (sender as RadRichTextBox).Document.EnumerateChildrenOfType<FieldRangeStart>().Reverse().ToList();
        foreach (FieldRangeStart rangeStart in dates)
        {
            if (rangeStart.Field is DateField)
            {
                (sender as RadRichTextBox).Document.UpdateField(rangeStart);
            }
        }
    }
    Feel free to get back to us if you have other comments or questions.
     

    Kind regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top