This is a migrated thread and some comments may be shown as answers.

BUG - Auto-update DateTime fields not working?

1 Answer 61 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 06 Dec 2012, 06:26 PM
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 

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 11 Dec 2012, 11:06 AM
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.

Tags
RichTextBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or