FormField value formatting changes- when value changes

How can i keep the formatting of my formfields values (fontsize,family, bold…) when using FF.SetTextInputValue()

See the attached template and the resulting document.

Now i noticed, that this problem occours only if i change formfield formatting only. If i format formfield together with some text, there are no problems.

See attached Sample.

Yes, this problem was discussed earlier and the workaround is exactly like you have described. Great that you have found it by yourself though. I will check if we can fix this issue as it really looks ugly the way it is. I will inform you of the results here in this thread.

Best regards,

I have checked that thread before posting my post. My problem isn’t quite the same. I need to keep the existing formatting.

When I was debuging I noticed that formfield.Font.Bold is set on true (which is correct), but there is no setter or any other method to set back Font with original properties. I was also thinking about writing a method that would store each Font object property and then recall it (set properties back to some Font object of a formfield).

Is there any way temporarily solve this problem until the problem is fixed?

When can I expect a version with this problem fixed?

Thank you!

I have logged this problem to our defect base as issue #1224. We will try to fix it in the next release which will be published in a few weeks.

Best regards,

Any progress with the bug?

We are planing to buy an OEM licence as soon as this bug is fixed.

I cannot say for sure if it will be fixed in the next version as it requires some redesign of several internal classes. I am looking for a workaround now and will notify you if I will find a suitable way to do this with the current API.

Best regards,

Perfect! a workarround would be great!!!

Here is a method that seems to work fine for your task:

public void TestDefect1224Workaround()
{
    Document doc = TestUtil.Open(@“Defects\TestDefect1224.doc”);
    SetFormFieldText(doc.Range.FormFields[“Besedilo1”], “BOLD”);
    SetFormFieldText(doc.Range.FormFields[“Besedilo2”], “Normal”);
    SetFormFieldText(doc.Range.FormFields[“Besedilo3”], “Green Italic”);
    TestUtil.SaveShow(doc, @“Defects\TestDefect1124 Out.doc”);
}

private void SetFormFieldText(FormField formField, string text)
{
    Node node = formField;
    while (node != null && node.NodeType != NodeType.FieldSeparator)
    {
        node = node.NextSibling;
    }

    node = node.NextSibling;
    if (node is Run)
    {
        ((Run)node).Text = text;
    }

    node = node.NextSibling;
    while (node != null && node.NodeType != NodeType.FieldEnd)
    {
        if (node is Run)
        {
            node.Remove();
        }
        node = node.NextSibling;
    }
}

Please try it and let me know if it works ok on your templates.

Best regards,

Try your function with the attached document. Some of the fields are not bold anymore when you change their value with function you provided.

I forgot to mention before that we also use date and number formfield types and change value by setting a formfield value to an object that can be date, string or datetime.

Ok, try using the following code instead:

private void SetFormFieldText(FormField formField, object value)
{
    Node node = formField;
    Node separator = null;
    Run resultRun = null;
    while (node != null && node.NodeType != NodeType.FieldSeparator)
    {
        node = node.NextSibling;
    }
    separator = node;
    while (node != null && node.NodeType != NodeType.FieldEnd)
    {
        if (node is Run)
            resultRun = (Run)node.Clone(true);
        node = node.NextSibling;
    }
    formField.SetTextInputValue(value);
    if (separator != null && resultRun != null)
    {
        resultRun.Text = separator.NextSibling.GetText();
        separator.ParentNode.InsertAfter(resultRun, separator);
        resultRun.NextSibling.Remove();
    }
}

It recognizes the field data type and applies the formatting strings correctly.

Numbers and dates are now working but some formfields still lose their
formating. Please try to change formfield values to previously attached
template with your function.

Can you create this thread non-private. I accidently marked “Keep this post private” in my last post.

Yes, I have seen your previous note that some form fields still loose their formatting when their value is updated with the given method. I have tested it with both of your templates but have not noticed any change in formatting. Please point out exactly where and what formatting is lost, maybe I have just overlooked it.

I have marked your previous post as not-private.

Best regards,

In my template all formfileds are bold. In generated document some of them loose boldness…

I can provide more problematic templates for testing if you need them.

Attached is the result of running the following code:

public void TestDefect1224B()
{
    Document doc = TestUtil.Open(@"NPXXX.dot");
    foreach (FormField formField in doc.Range.FormFields)
    {
        switch (formField.TextInputType)
        {
            case TextFormFieldType.DateText:
                SetFormFieldText(formField, DateTime.Now);
                break;
            case TextFormFieldType.NumberText:
                SetFormFieldText(formField, 1234);
                break;
            case TextFormFieldType.RegularText:
                SetFormFieldText(formField, "some text");
                break;
        }
    }
    TestUtil.SaveShow(doc, @"TestDefect1124B Out.doc");
}

private void SetFormFieldText(FormField formField, object value)
{
    Node node = formField;
    Node separator = null;
    Run resultRun = null;
    while (node != null && node.NodeType != NodeType.FieldSeparator)
    {
        node = node.NextSibling;
    }
    separator = node;
    while (node != null && node.NodeType != NodeType.FieldEnd)
    {
        if (node is Run)
            resultRun = (Run)node.Clone(true);
        node = node.NextSibling;
    }
    formField.SetTextInputValue(value);
    if (separator != null && resultRun != null)
    {
        resultRun.Text = separator.NextSibling.GetText();
        separator.ParentNode.InsertAfter(resultRun, separator);
        resultRun.NextSibling.Remove();
    }
}

As far as I can see no formatting is lost.

I tested the code again. It looks like that formatting stays as it should.
Thank you for the code.