简体   繁体   English

spark combobox数据提供程序验证器

[英]spark combobox dataprovider validator

I want to give validations to the spark combobox when user enters a value other than the value in the dataprovider of that combobox.Can any one give me the code how to give validation if user enters a value other than the value in the dataprovider and on focus change validation should occur. 当用户输入的值不是该组合框的数据提供程序中的值时,我想对spark组合框进行验证。如果用户输入的值不是dataprovider中的值,则可以给我代码如何进行验证的代码应进行焦点变更验证。 Thanks 谢谢

you can set the property textInput to the combobox, and manage the check on input from the associated function... 您可以将属性textInput设置为组合框,并管理关联函数的输入检查...

<fx:Script>
    <![CDATA[
        protected function change(event:TextEvent):void
        {

        }
    ]]>
</fx:Script>

<s:ComboBox  textInput="change(event)"/>

flash.display.InteractiveObject.textInput flash.display.InteractiveObject.textInput

Dispatched when a user enters one or more characters of text. 当用户输入一个或多个文本字符时调度。 Various text input methods can generate this event, including standard keyboards, input method editors (IMEs), voice or speech recognition systems, and even the act of pasting plain text with no formatting or style information. 各种文本输入法都可以生成此事件,包括标准键盘,输入法编辑器(IME),语音或语音识别系统,甚至包括不带格式或样式信息的纯文本粘贴操作。

Event Type: 事件类型:
flash.events.TextEvent.TEXT_INPUT flash.events.TextEvent.TEXT_INPUT

EDIT 编辑

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.controls.Alert;
        import mx.events.FlexEvent;
        //dataprovider initialization
        [Bindable]private var d:ArrayCollection = new ArrayCollection([
            {name: "Values 1"}, {name: "Values 2"}, {name: "Values 3"}
            ]);

        protected function change(event:TextEvent):void
        {      // if enter key is pressed
            if (event.text.charAt(event.text.length-1) == "\r")
            {       
                // if the text inserted in the combobox is one of the 
                // item in the dataprovider 
                if (comboBox.selectedIndex >= 0)
                    Alert.show("something selected");
                else   // if the text is not an item in the dataprovider
                    Alert.show("nothing selected");

            }
        }
    ]]>
</fx:Script>

<s:ComboBox id="comboBox" textInput="change(event)"
       dataProvider="{d}" labelField="name"/>

EDIT 2 编辑2

To set the border color from actionscript you can do: 要设置动作脚本的边框颜色,您可以执行以下操作:

comboBox.setStyle("borderColor","#ff0000"); // set the bordercolor to red

If you do not need particular check on the text inserted you can simply set the property change on the ComboBox 如果您不需要特别检查插入的文本,则只需在ComboBox上设置属性更改即可

        protected function index_change(event:IndexChangeEvent):void
        {
            if (comboBox.selectedIndex >= 0 )
                Alert.show("something selected")
            else
                Alert.show("nothing selected");

        }
        <s:ComboBox id="comboBox" dataProvider="{d}" labelField="name"
            change="index_change(event)"
             />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM