简体   繁体   English

Flex DateField / DateChooser问题

[英]Flex DateField / DateChooser Issue

We use the mx:DateField for our Dates and editable="true" so that we can either choose a date or enter it as well. 我们使用mx:DateField作为日期,并使用editable =“ true”,以便我们可以选择一个日期或也可以输入一个日期。 The requirement is that we should not be able to enter more than 10 characters in this field (10/10/2010). 要求是我们在此字段中输入的字符数不能超过10个(2010年10月10日)。 But the DateField does not have the maxChars property to restrict that. 但是DateField没有maxChars属性来限制它。

So we tried to use a Text Field + DateChooser to restrict the number of characters. 因此,我们尝试使用文本字段+ DateChooser来限制字符数。 Everything works as desired, but the issue is that the DateChooser shows the whole calendar on the page and not as a Calendar icon that will popup a calendar (as DateField). 一切都按预期工作,但问题在于DateChooser在页面上显示了整个日历,而不是作为会弹出日历的Calendar图标(作为DateField)。

So now my q is 所以现在我的q是

1) Using the DateField, how can I restrict the number of characters that can be entered in the text field to 10 1)使用DateField,如何将可在文本字段中输入的字符数限制为10

or 要么

2) Using the DateChooser, how can I change the appearance of it to show a Calendar Icon and then show the calendar as popup on clicking it (similar to DateField). 2)使用DateChooser,如何更改其外观以显示“日历”图标,然后单击该日历时将其显示为弹出窗口(类似于DateField)。

If anyone can help me on this, that would be wonderful. 如果有人可以帮助我,那将是美好的。

Start with something like this: 从这样的事情开始:

<s:TextInput click="dc.visible=!dc.visible" maxChars="10" />
<mx:DateChooser id="dc" visible="false" />

From here you just need to handle click events to the date chooser and fill out the textinput appropriately 从这里,您只需要处理日期选择器的点击事件并适当地填写textinput

UPDATE: In attempt to answer your questions from comments 更新:试图通过评论回答您的问题

UI: 用户界面:

<s:HGroup>
    <s:TextInput id="dateInput" click="dateInput_clickHandler(event)" maxChars="10" />
    <mx:DateChooser id="dc" visible="false" includeInLayout="false" change="dc_changeHandler(event)" />
</s:HGroup>

Script: 脚本:

protected function dateInput_clickHandler(event:MouseEvent):void
{
    dc.includeInLayout = !dc.includeInLayout;
    dc.visible = !dc.visible;
}

protected function dc_changeHandler(event:CalendarLayoutChangeEvent):void
{       
    dateInput.text = dateFormatter.format(event.newDate);
    dateInput_clickHandler(null);
}

Declarations: 声明:

<mx:DateFormatter id="dateFormatter" formatString="MM/DD/YYYY" />

Hope this helps! 希望这可以帮助! -Ian -Ian

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

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