gpt4 book ai didi

actionscript-3 - 弹性 : How to control spacing between form item and corresponding errorString?

转载 作者:行者123 更新时间:2023-12-01 02:27:46 24 4
gpt4 key购买 nike

这是一个简单的应用程序来说明我的问题。指示:

  • 运行附加的 Flex 4 代码
  • 在第一个表单项中输入 0(例如“输入速度 (MPH)”)
  • 单击第二个表单项
  • 观察错误字符串出现在第一个表单项的右侧

  • 问题:如何使错误字符串直接出现在第一个表单项的右侧,同时保持表单的宽度固定(例如,当前示例使用固定的表单宽度 400 px)?
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
    <![CDATA[
    private function validateSpeed():void {
    var num:Number=Number(speedId.text);
    speedId.errorString="";

    if (speedId.text=="") {
    speedId.errorString="This field is required.";
    return;
    } else if ( Number(speedId.text)<1000) {
    speedId.errorString="The speed must be at least 1 MPH.";
    return;
    } else if ( Number(speedId.text)>1e11) {
    speedId.errorString="The speed cannot exceed 100 MPH.";
    return;
    }
    }
    ]]>
    </fx:Script>

    <s:Form width="600" >
    <s:layout>
    <s:FormLayout gap="-10" horizontalAlign="center"/>
    </s:layout>

    <s:FormItem id="speedFI" label="Enter Speed (MPH):" width="600" required="true">
    <s:TextInput id="speedId" width="195" textAlign="right"
    restrict="0-9" maxChars="7"
    focusOut="validateSpeed();"
    toolTip="Enter a speed between 1 and 100 MPH."/>
    </s:FormItem>

    <s:FormItem id="dummyFI" label="Dummy Label:" width="600" required="true">
    <s:TextInput id="dummyId" width="195" textAlign="center"
    restrict="0-9" maxChars="7" prompt="Click here after entering 0 above."
    toolTip="Dummy form item."/>
    </s:FormItem>
    </s:Form>
    </s:Application>

    最佳答案

    您可以通过自定义 FormItemSkin 来控制错误信息的定位.

    以下是默认 FormItemSkin 中的一些片段类(class)。请注意,此皮肤使用“约束”列/行来排列各个部分。您可以修改列的定义或修改“helpColumn”中错误消息的位置。有很多其他方法可以解决这个问题,但看起来您需要在皮肤内部这样做。

    约束列/行声明:

    <s:layout>
    <s:FormItemLayout>
    <s:constraintColumns>
    <!--- The column containing the sequence label. -->
    <s:ConstraintColumn id="sequenceCol" />
    <!--- The column containing the FormItem's label. -->
    <s:ConstraintColumn id="labelCol" />
    <!--- The column containing the FormItem's content. -->
    <s:ConstraintColumn id="contentCol" width="100%"/>
    <!--- The column containing the FormItem's help content. -->
    <s:ConstraintColumn id="helpCol" maxWidth="200"/>
    </s:constraintColumns>
    <s:constraintRows>
    <!--- @private -->
    <s:ConstraintRow id="row1" baseline="maxAscent:10" height="100%"/>
    </s:constraintRows>
    </s:FormItemLayout>
    </s:layout>

    这是用于显示错误消息的标签对象。您可以使用以下内容将标签的左边缘设置为更靠近输入字段: left="helpCol:10" (而不是 helpCol:27 )。
    <s:RichText id="errorTextDisplay" includeIn="errorStates"
    fontStyle="italic" fontWeight="normal" color="0xFE0000"
    left="helpCol:27" right="helpCol:10"
    bottom="row1:10" baseline="row1:0"
    maxDisplayedLines="-1"/>

    关于actionscript-3 - 弹性 : How to control spacing between form item and corresponding errorString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036478/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com