C

LabelTextValidatingEventArgs

Event arguments for label text validation.

Remarks

Event handlers can set the validatedText property to null to cancel label editing if validation failed, or set the validatedText property to a changed, validated value.

Validation can also be performed asynchronously by assigning a promise to the validatedText property.

Members

Show:

Constructors

Initializes a new instance of the LabelTextValidatingEventArgs class.

Parameters

context: IInputModeContext
The context.
label: ILabel
The label.
newText: string
The initial new text as entered by the user.

Properties

Gets the context for the current event.
readonlyfinal

Property Value

The context.
Gets the label that is being edited.
Note that the label might not belong to a graph if it is a helper for a label that is about to be created.
readonlyfinal

Examples

Labels with tag "int label" should be rejected if their text cannot be parsed into an integer value:
graphEditorInputMode.editLabelInputMode.addEventListener(
  'validate-label-text',
  (evt) => {
    if (
      evt.label.tag === 'int label' &&
      Number.isNaN(parseInt(evt.newText))
    ) {
      evt.validatedText = null
    }
  },
)
Gets the new text to use for the label.
readonlyfinal

Property Value

The new text.

Examples

Labels with tag "int label" should be rejected if their text cannot be parsed into an integer value:
graphEditorInputMode.editLabelInputMode.addEventListener(
  'validate-label-text',
  (evt) => {
    if (
      evt.label.tag === 'int label' &&
      Number.isNaN(parseInt(evt.newText))
    ) {
      evt.validatedText = null
    }
  },
)
Gets or sets the validated text, or a Promise<T> resolving with the new text to use for the label.
Assigning null or resolving the Promise<T> with null indicates that the validation has failed.
final

Property Value

The new text, or a Promise<T> resolving with the new text.

Examples

Call an async method that checks if the new label text should be accepted:
graphEditorInputMode.editLabelInputMode.addEventListener(
  'validate-label-text',
  (evt) => {
    // call checkIfTextIsValid which returns a Promise<bool>
    evt.validatedText = checkIfTextIsValid(evt.newText).then(
      (isValidText) => (isValidText ? evt.newText : null),
    )
  },
)

See Also

Developer's Guide