Event arguments for label text validation.
Inheritance Hierarchy
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.
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.
Gets the context for the current event.
Gets the label that is being edited.
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
}
},
)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.
Gets or sets the validated text, or a Promise<T> resolving with the new text to use for the label.
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