FormField default value in Microsoft Word document

How I can modify default FormField value in Microsoft Word documents (DOC, DOCX)? In Microsoft Word interop it is value of Interop.Word.FormField.TextInput.Default property.

Hi

Thanks for your inquiry. Unfortunately, there is no way to specify “Default text” property of text input form field. You can only specify displayed text using FormField.Result property or using FormField. SetTextInputValue method.

You will be notified as soon as it is possible to specify “Default text”.

Best regards,

Thanks.

We also need this functionality. I have attached a Word 2007 file containing examples of both. One is a legacy field, one is a regular text field.

If it were to be implemented, I would assume that a FormField.Default property would need to
return either

<w:t>Click here to enter text.</w:t>

or

<w:default w:val="This is default text"/>

from document.xml depending on whether it was a legacy form field on not.
Thanks,
Jeff Montgomery

Hi

Thanks for your request. The first one is not actually a formafield. It is Structured Document Tag (or Content Control). You change it’s text by changing nodes inside STD:

https://reference.aspose.com/words/net/aspose.words.markup/structureddocumenttag/

Best regards,

Is this accessible using code? I don’t see any examples and the forum link at the bottom seems to indicate that it’s not publicly accessible.
Thanks,
Jeff
P.S. - I will hope that a future version will also provide support for the DefaultText property. Our Office add-in currently supports this using the MS Word API, and we were in the middle of converting to the Aspose API when we realized this property is not supported. We allow the user to specify default text, and without API support our product will lose this capability.

Hi Jeff,

Thanks for your inquiry.

Sure you can access this through code. The default text of a Structured document tag is stored as child nodes just like any other content of the control.

For example you can easily find the text and change it like below:

StructuredDocumentTag tag = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

// Get the text of the content control
string tagText = tag.ToTxt();

// Replace the text with something else.
tag.Range.Replace(tag.ToTxt(), "New Text", false, false);

If you need to check if the content of the tag is default text or proper content you can check the Runs of text like in the code below.If the text is default then the StyleIdentifier will be “PlaceholderText”.

// Find if the current text of the control is the default text or not.
// Retrieve the first run of the control.
Run firstRun = (Run)tag.GetChild(NodeType.Run, 0, true);
bool isDefaultText;

if (firstRun == null)
    isDefaultText = false;
else
    isDefaultText = firstRun.Font.StyleIdentifier == StyleIdentifier.PlaceholderText ? true : false;

We will inform you when a property is available to quickly retrieve the default text of a content control.

Thanks,

Thanks for the examples by the way.
Just wondering if there are any updates on getting the DefaultText property in the Aspose.Words API, as in the MS API. I’ve finished the first pass of coding our project, and this is the one remaining issue.
Jeff Montgomery

Hi Jeff,

Thanks for your request. Unfortunately, this feature is not available yet. We will keep you informed regarding status of the appropriate issue and let you know once this feature is available.

Best regards,

One of our developers noticed the property FormField.TextInputDefault, which the Aspose.Words API documentation states will populate the form field if no value is specified. This is the functionality requested by users on this thread. However, it does not appear to work. The API documentation states the following:
“When TextInputType is Regular or Number, this string specifies the default string for the text form field.”
However if I set the form field value to an empty string, Word does not display the text from TextInputDefault. For example:

oFormField.TextInputDefault = "This is a default value.";
oFormField.SetTextInputValue(string.Empty);
document.Save(destFileName2000);

Does this not work?
Jeff Montgomery

Hi Jeff,
Thanks for your inquiry.
I managed to reproduce the issue on my side. I have linked your request to the appropriate issue. We will inform you of any developments.
In the mean time you can use this code instead which should produce the correct output.

formField.TextInputDefault = "Default Text";
formField.Result = formField.TextInputDefault;

Thanks,

The issues you have found earlier (filed as 9321) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(28)

Hi,
I’m not seeing any change. See attached project. Do I have to do something else to get the default text to show up?
Thanks,
Jeff Montgomery

Hi Jeff,

Thanks for your request. The current Aspose.Words API allows you setting default text of form fields. For instance see the following code:

Document doc = new Document(@"Test001\in.doc");

string text = "my default text";
FormField field = doc.Range.FormFields[0];

// Set default text.
field.TextInputDefault = text;

// If you need that default text will apear imediately, just set it as a value.
field.SetTextInputValue(text);

doc.Save(@"Test001\out.doc");

Best regards,

The issues you have found earlier (filed as WORDSNET-4256) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(6)

The issues you have found earlier (filed as WORDSNET-4539) have been fixed in this Aspose.Words for .NET 21.4 update and this Aspose.Words for Java 21.4 update.