Event arguments for label text validation.
Inheritance Hierarchy
EventArgs
InputModeEventArgs
LabelTextValidatingEventArgs
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.
Type Details
- yFiles module
- view
Constructors
Initializes a new instance of the LabelTextValidatingEventArgs class.
Parameters
options - Object
A map of options to pass to the method.
A map of options to pass to the method.
- 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 label that is being edited.
Remarks
Note that the label might not belong to a graph if it is a helper for a label that is about to be created.
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.
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.
Remarks
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),
)
},
)