Skip to content

UIControl: return event ​

The return event fires after the user presses the Return key on the keyboard.

Syntax ​

addEventListener('return', (event) => { })

Event object ​

A plain Event with no fields other than type and target. It has no touch location: reading location gives undefined. It is a text input event and has nothing to do with touch points.

It cannot be canceled: cancelable is false, and preventDefault() has no effect.

When it fires ​

  • Fired by UITextField.
  • It fires after the Return key has taken effect and cannot be canceled. To intercept it beforehand, use the text field's cancelable beforereturn.
  • For whether the text field ends editing after Return, see UITextField.

Examples ​

js
const field = new UITextField();
field.addEventListener('return', () => {
  console.log('Submit:', field.text);
});

Effect: When the user presses Return in the text field, the console prints the text field's text.

Corresponding iOS API ​

UIControlEventEditingDidEndOnExit. Natively it is registered with addTarget:action:forControlEvents:; here, use addEventListener().

See also ​