研究调查问卷:请告诉我们您使用 Blockly 的体验
开始调查问卷
blockly >字段 >setValidator
Field.setValidator() 方法
为可编辑字段设置新的验证函数,或清除以前设置的验证器。
验证器函数会接受新字段值,并返回经过验证的值。经过验证的值可以是输入值、输入值的修改版本或 null(用于取消更改)。
如果函数不返回任何内容(或返回未定义的值),则新值会被认为是有效值。这样可以让字段使用经过验证的函数作为字段级更改事件通知。
Signature:
setValidator(handler: FieldValidator<T>): void;
参数
返回:
void
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-22。
[null,null,["最后更新时间 (UTC):2024-08-22。"],[[["The `setValidator()` method allows assigning a function to validate user input in editable fields, or removing a previously set validation function."],["Validators receive the new field value and return a validated version, potentially modified or null to reject the change."],["If the validator doesn't return a specific value, the input is accepted, offering a mechanism for change notifications."],["This method is used within Blockly's Field class to ensure data integrity and control user interactions."]]],["The `setValidator()` method configures or removes a validation function for editable fields. This function, provided as a `handler`, receives the new field value and returns either a validated value, a modified value, or `null` to prevent the change. Returning nothing or `undefined` accepts the new value. The `handler` parameter can also be set to `null` to clear an existing validator. It takes a `FieldValidator` type and returns `void`.\n"]]