insert_text_input method
insert_text_input(name, type, format, field_value, max_length)
Inserts a text form field at the current position.
def insert_text_input(self, name: str, type: aspose.words.fields.TextFormFieldType, format: str, field_value: str, max_length: int):
...
Parameter | Type | Description |
---|---|---|
name | str | The name of the form field. Can be an empty string. |
type | TextFormFieldType | Specifies the type of the text form field. |
format | str | Format string used to format the value of the form field. |
field_value | str | Text that will be shown in the field. |
max_length | int | Maximum length the user can enter into the form field. Set to zero for unlimited length. |
Remarks
If you specify a name for the form field, then a bookmark is automatically created with the same name.
Returns
The form field node that was just inserted.
Examples
Shows how to create form fields.
builder = aw.DocumentBuilder()
# Form fields are objects in the document that the user can interact with by being prompted to enter values.
# We can create them using a document builder, and below are two ways of doing so.
# 1 - Basic text input:
builder.insert_text_input('My text input', aw.fields.TextFormFieldType.REGULAR, '', 'Enter your name here', 30)
# 2 - Combo box with prompt text, and a range of possible values:
items = ['-- Select your favorite footwear --', 'Sneakers', 'Oxfords', 'Flip-flops', 'Other']
builder.insert_paragraph()
builder.insert_combo_box('My combo box', items, 0)
builder.document.save(file_name=ARTIFACTS_DIR + 'DocumentBuilder.CreateForm.docx')
Shows how to insert a text input form field into a document.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Insert a form that prompts the user to enter text.
builder.insert_text_input('TextInput', aw.fields.TextFormFieldType.REGULAR, '', 'Enter your text here', 0)
doc.save(file_name=ARTIFACTS_DIR + 'DocumentBuilder.InsertTextInput.docx')
Shows how to insert a text input form field.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.write('Please enter text here: ')
# Insert a text input field, which will allow the user to click it and enter text.
# Assign some placeholder text that the user may overwrite and pass
# a maximum text length of 0 to apply no limit on the form field's contents.
builder.insert_text_input('TextInput1', aw.fields.TextFormFieldType.REGULAR, '', 'Placeholder text', 0)
# The form field will appear in the form of an "input" html tag, with a type of "text".
doc.save(file_name=ARTIFACTS_DIR + 'FormFields.TextInput.html')
See Also
- module aspose.words
- class DocumentBuilder