//继承验证
public class ObjectNullValidator extends Validator
{
public function ObjectNullValidator()
{
super();
requiredFieldError = "必须填写" ;
}
private var _invalidCode:String = "222";
public static function validateString(validator:ObjectNullValidator, value:Object, baseField:String = null, aa:Boolean = false):Array
{
var results:Array = [];
if (!aa)
{
if (value==null)
results.push(new ValidationResult(true, baseField, "222", validator.requiredFieldError));
}
return results;
}
override protected function doValidation(value:Object):Array
{
var results:Array = super.doValidation(value);
var val:String = value ? String(value) : "";
if (results.length > 0 || ((val.length == 0) && !required))
return results;
else
return ObjectNullValidator.validateString(this, value, null, required );
}
public function get invalidCode():String
{
return _invalidCode;
}
}
//组件调用
<valid:ObjectNullValidator source="{_setmeal}"
property="selectedItem"
required = "true"
requiredFieldError = "(必选项)"
triggerEvent = "focusOut"/>