1
與javascript類似,並執行IronValidatorBehavior
如何在聚合物飛鏢中進行自定義驗證?如何在聚合物飛鏢中進行自定義驗證
我可以創建一個新的自定義驗證器,它實現了IronValidatorBehavior
<dom-module id="form-input">
<template>
<style include='shared-styles iron-flex iron-flex-alignment'>
:host {
display: block;
padding: 1em;
}
</style>
<custom-validator id="validator" validator-name="jsonValidator" validator-type="json"></custom-validator>
<paper-textarea label="[[label]]" id="body" name="body" autofocus tabindex="0"
validator="jsonValidator" auto-validate error-message="This is not a valid format"></paper-textarea>
</template>
</dom-module>
的自定義驗證寫爲
library main_app.custom_validator;
import 'dart:html';
import 'package:polymer/polymer.dart';
import 'package:polymer_elements/iron_validator_behavior.dart' show IronValidatorBehavior;
@PolymerRegister('custom-validator')
class CustomValidator extends PolymerElement with IronValidatorBehavior{
CustomValidator.created() : super.created();
@reflectable
bool validate(e, [_]){
switch(validatorType) {
case 'json':
return textValidator(e);
}
return false;
}
bool textValidator(e){
return false;
}
}