is_dirty property

Field.is_dirty property

Gets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.

def is_dirty(self) -> bool:

def is_dirty(self, value: bool):


Shows how to use special property for updating field result.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
# Give the document's built-in "author" property value, and then display it with a field. = 'John Doe'
field = builder.insert_field(aw.fields.FieldType.FIELD_AUTHOR, True).as_field_author()
self.assertEqual('John Doe', field.result)
# Update the property. The field still displays the old value. = 'John & Jane Doe'
self.assertEqual('John Doe', field.result)
# Since the field's value is out of date, we can mark it as "dirty".
# This value will stay out of date until we update the field manually with the Field.update() method.
field.is_dirty = True
with io.BytesIO() as doc_stream:
    # If we save without calling an update method,
    # the field will keep displaying the out of date value in the output document., aw.SaveFormat.DOCX)
    # The LoadOptions object has an option to update all fields
    # marked as "dirty" when loading the document.
    options = aw.loading.LoadOptions()
    options.update_dirty_fields = update_dirty_fields
    doc = aw.Document(doc_stream, options)
    self.assertEqual('John & Jane Doe',
    field = doc.range.fields[0].as_field_author()
    # Updating dirty fields like this automatically set their "is_dirty" flag to False.
    if update_dirty_fields:
        self.assertEqual('John & Jane Doe', field.result)
        self.assertEqual('John Doe', field.result)

See Also