简体   繁体   English

在 Flex 中将允许的范围设置为 DateField?

[英]Setting permitted range to DateField in Flex?

I have a Flex screen (MXML) with two date fields (say, From and To date).我有一个带有两个日期字段(例如,从日期和到日期)的 Flex 屏幕 (MXML)。 Based on the date values, data has to be shown on the DataGrid.根据日期值,数据必须显示在 DataGrid 上。 Here, I have to restrict the user on choosing the date value.在这里,我必须限制用户选择日期值。 A permitted range has to be set in the date field.必须在日期字段中设置允许的范围。

Eg, The default date for both date fields is "Today" The permitted range for From Date is "Today - 7 to Today" The permitted range for To Date is also "Today - 7 to Today"例如,两个日期字段的默认日期是“今天” 从日期的允许范围是“今天 - 7 到今天” 到日期的允许范围也是“今天 - 7 到今天”

How can I achieve this?我怎样才能做到这一点? Both by selecting the date picker as well as by entering the date value if the date field is set to editable通过选择日期选择器以及在日期字段设置为可编辑时输入日期值

I would simply implement a custom DateValidator for this kind of logic especially that users can also type-in certain dates in invalid or not supported format.我会简单地为这种逻辑实现一个自定义的DateValidator ,尤其是用户还可以以无效或不受支持的格式输入某些日期。

ActionScript (pseudo-code): ActionScript(伪代码):

public class RangeDateValidator extends DateValidator
{
    [Bindable]
    public var fromDate:String;

    protected override function doValidation(value:Object):Array 
    {
        // create a real date and apply your custom logic
        // based on the fromDate value
    }
}

MXML (pseudo-code): MXML(伪代码):

<d:RangeDateValidator source="{ toDate }" property="text" 
    inputFormat="DD.MM.YYYY" fromDate="{ fromDate.text }" />

Let me know if this is working in your case让我知道这是否适用于您的情况

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

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