我正在尝试对 mxml 文件中的三个字段进行验证。其中两个是必需的,一个不是。我只想在输入内容时验证邮政编码字段。如果它是空白的,那么我想允许启用“提交”按钮,只要正确设置了其他两个必填字段。代码:
<mx:EmailValidator id="emailValidator"
property="text" source="{ownerName}"
valid="emailValidator_validHandler(event)"
invalid="emailValidator_validHandler(event)"/>
<mx:ZipCodeValidator id="zipCodeValidator"
property="text" source="{zip}"
required="false"
valid="zipCodeValidator_validHandler(event)"
invalid="zipCodeValidator_validHandler(event)"/>
<mx:Validator id="roomNameValidator"
property="text" source="{roomName}"
valid="roomNameValidator_validHandler(event)"
invalid="roomNameValidator_validHandler(event)"/>
[Bindable]
private var isRoomNameValid:Boolean;
[Bindable]
private var isOwnerValid:Boolean;
[Bindable]
private var isZipValid:Boolean;
protected function emailValidator_validHandler(event:ValidationResultEvent):void
{
isOwnerValid = (event.type==ValidationResultEvent.VALID);
}
protected function zipCodeValidator_validHandler(event:ValidationResultEvent):void
{
isZipValid = (event.type == ValidationResultEvent.VALID);
}
protected function roomNameValidator_validHandler(event:ValidationResultEvent):void
{
isRoomNameValid = (event.type==ValidationResultEvent.VALID);
}
然后我尝试设置提交按钮的启用属性:
enabled = "{isOwnerValid && isRoomNameValid && zip.text.length>0?isZipValid:true}"
但它不起作用。即使邮政编码字段显示红色边框,我仍然可以在邮政编码字段中提交错误数据。