Flex - 输入数据时的格式输入(日期字段/日期)?
我在 Flex 中使用 mx:DateField,它与日期选择器配合得很好,但我也需要它可编辑,所以我设置 editable="true"。
问题是,现在用户可以输入他们想要的任何内容 - 即使我设置了 formatString="YYYY-MM-DD"。日期选择器遵循此格式,但如果用户以 MM/DD/YYYY 格式输入,他们可以 - 或者甚至可以输入垃圾数据。
我意识到我可以设置一个数据验证器来检查它是否是一个有效的日期并且按照flex文档采用适当的格式,但我希望有一些我在其他语言中看到的东西,其中文本字段会显示类似“ 0000-00-00”,用户单击进入该字段,它允许他们仅更改数字(零),并且不能键入任何字母字符或添加/删除任何长度。
有什么想法吗?
I am using an mx:DateField in Flex and it works nice with the date picker, but I also need it to be editable, so i set editable="true".
The problem is that now the user can enter anything they want - even though I have a formatString="YYYY-MM-DD" set. The date picker honors this format, but if the user enters in the format MM/DD/YYYY they can - or they can even enter garbage data.
I realize I can set up a data validator to check that it is a valid date and in the appropriate format as per the flex docs, but I was hoping to have something I have seen in other languages where the text field would show something like "0000-00-00" and the user clicks in to the field and it allows them to change only the digits (the zeros) and can not type any alpha characters or add/remove any length.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用屏蔽文本输入。
Try to use masked text input for that.
就我个人而言,我不会使用 DateField。我将创建一个自定义组件,它有 3 个单独的 TextInput,一个代表每年、每月和一天,如果用户想要手动选择日期,则在右侧有一个 DateChooser。
您必须添加逻辑以使焦点从一个文本输入跳到下一个文本输入。您甚至可以使它们看起来像是在同一个组件中,但中间有破折号。用户认为它只是一个组件,但实际上它是一个复合组件。
不管怎样,只要我的 2 美分。我以前做过,效果很好。
Personally, I wouldn't use a DateField. I would create a custom component that has 3 separate TextInputs, one for each year, month and day, and have a DateChooser on the right side if the user wants to pick the date manually.
You'll have to add logic to have the focus bounce from one textinput to the next. You can even make them look like they're in the same component with dashes in between. The user thinks it's just one component, but it's actually a composite component.
Anywho, just my 2 cents. I've done it before with good results.