Writer: how to make a field that automatically updates with a form control value

OK, trying to switch from MS Word to LibreOffice Writer and experimenting with the latter. I need to figure out a way to create a document that contains two things: a simple edit box and a text field that automatically contains whatever text the user will enter into the edit box.

In MS Word it looks like this:

Untitled

Basically here the first line has a legacy edit box with a bookmark name assigned to it (let’s call it “Text1”. Importantly, the legacy edit box has “Calculate on exit” option checked. And the second line contains { REF Text1 } field.

Then you protect the document allowing only form filling and every time you type something in the control (edit box) and tab out of it, the second line text gets updated with whatever you have typed.

So now I am trying to do the same in LibreOffice Writer. So far I have figured out how to do the following:

  1. I know how to create form controls (I was pleasantly surprised, they are much richer than in Word, this is the main reason I want to switch to LibreOffice Writer)
  2. I know how to create a bookmark around specific fixed text in the document
  3. I know how to create a cross-reference field that shows text content of a previously created bookmark

What I can’t figure out is how to link 1 with 2 and 3 so that the cross-reference field (or any other more appropriate field) shows the content of the form control and not a fixed bookmarked text.

If bookmarking is a way to solve this problem (like in Word), I can’t find a way to appoint a bookmark name to the form control and I also do not see any equivalent of “Calculate on exit” when I look at the form control properties.

I did try manually creating a bookmark around entire form control, but it did not ingest the content of the control (basically whatever I type is not getting reflected in the cross-reference field).

Does anyone know what I am missing?

Form controls are intended to create “stand alone” forms. By stand alone, I mean control values don’t interfere with text. They must be retrieved through macros and your code will make some use of them.


If your goal is “simply” to change some content or behaviour of a text document, without sophisticated processing, you can do with fields.


I see two ways: variables or user field combined with input field.

Variables

This is probably the most error-prone if you’re a beginner in Writer.

After "Input field: " text:

  1. Insert>Field>More Fields, Variables tab
  2. Type Set Variable, Format whatever you need, Name: variable name
  3. Value: the contents of your “input field”
  4. Insert

When you want to echo the value

  1. Insert>Cross-reference, Variables tab
  2. Type Show variable, Select the variable name
  3. Insert

This returns the most recent value of the variable.


To change the contents of the “input field”, double-click on it and change its value. Not as user-friendly as simply putting the cursor in a control and typing.


You have noticed I typed “most recent value” above. You can insert as many Set variable fields targeting the same variable. This redefines the value. Show variable retrieves the closest backward Set variable occurrence.

User field

Caveat emptor! In Writer field terminology, a user field is the data source, whereas in Word and in your question it is the data source. In Writer terminology again, an input field is the use of data. Pay special attention to this inversion.

Your “input field” is created with a User field:

  1. Insert>Field>More fields, Variables tab
  2. Type User field
  3. Format whatever you need
  4. Name: field name
  5. Value: the contents of your “input field”
  6. Insert

When you want to echo the value

  1. Insert>Cross-reference, Variables tab
  2. Type Input field, Select the field name
  3. Insert

You can insert the same User field several times but they are all “synchronised”, i.e. if you change the value in one occurrence, all other occurrences show the same value. This is the only difference with a variable.

Last points

There is no “protection mechanism” in Writer (which would somehow be contradictory with the application purpose).

Don’t try to make sophisticated computations with Writer; it is not intended for this.

Perhaps, creating a table would be a better solution since you can attach formulas to table cells (once again: rudimentary arithmetics, otherwise go for Calc). You can also cross-reference cell contents.

PS: when asking here, always mention OS name, LO version and save format. The last item is the most important. All I wrote about fields does not survive if document is not saved .odt-native (i.e. .doc(x)).