aWhere Manual
DevelopWidgets

Expression builder

Embed the expression builder that composes a text from your own words and the values of fields, and receive the text the user writes.

The expression-builder widget lets the user write a text with the values of fields inserted in it, and sends that text back to your page.

URL and parameters

The parameters that start with _ are the same for every widget. See Widgets.

ParameterMeaningRequired
schema_source_item_idThe id of the table that the fields come from. Without it the user can write only text.No
valueAn existing expression to edit.No

An expression is a text that uses {id} for the value of a field, such as {name} District {district}, where id is the id of the field in the table. The widget offers only fields of type String and Number that are not hidden.

Messages

This widget does not send ready and does not take post-widget-parameters. Every value is in the URL. For the other common messages see Widgets.

actionDirectionpayload
donewidget to your pageThe expression string that the user confirmed.
cancelwidget to your pageNone. The user closed it without an expression.

Example

const messageToken = crypto.randomUUID()
const params = new URLSearchParams({
  _credential_type: 'bearer-token',
  _token: token,
  _origin: location.origin,
  _message_token: messageToken,
  _locale: 'en',
  schema_source_item_id: tableItemId,
  value: '{name}',
})
frame.src = `${site}/widgets/expression-builder?${params}`

addEventListener('message', (e) => {
  if (e.origin !== site || e.data.messageToken !== messageToken) return
  if (e.data.action === 'done') save(e.data.payload) // for example '{name} District {district}'
  if (e.data.action === 'cancel') frame.remove()
})

On this page