日期字段掩码不工作 [英] Date Field Mask Not Working

查看:322
本文介绍了日期字段掩码不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是非常令人沮丧。我使用 cfinput datefield mask =MM / DD / YYYY如果它是 cfinput文本 mask =MM / DD / YYYY它工作完美。我不想只有一个文本框,虽然我想保留日期字段给你的日历...问题是,当他们使用日历,它是正确的格式MM / DD / YYYY,但如果用户只是类型在日期进入文本框而不使用日历,用户可以输入任何他们想要的(122334435),这显然是不可接受的。任何人都可能知道任何想法或解决方法?



工作原理:

 < cfform name =foo> 
< cfinput
type =text
name =test
validate =eurodate
mask =99/99/9999
validateat =onblur/>
< input type =submit>
< / cfform>

无效:

 < cfform name =foo> 
< cfinput
type =datefield
name =test
validate =eurodate
mask =MM / DD / YYYY
validateat =onblur/>
< input type =submit>
< / cfform>


解决方案

我添加了关于同一问题最初打开的其他问题。我会在这里张贴一点,因为用户可能会找到这个问题,而不是其他的。



我相信问题是掩码属性在< cfinput type =datefield... 代码只在使用Flash表单时有效 - 文档参考



我已强调文本

>

在cfcalendar标签和 Flash格式日期字段输入控件 中,使用以下掩码确定输出格式。您可以在掩码中使用大写或小写字符:



...



以下模式指定 Flash表单将使用日期字段输入控件选择的日期以文本形式发送到ColdFusion:



< cfinput name =startDatetype =datefieldlabel =date:mask =mm / dd / yyyy/>


因为你没有使用Flash表单,面具不适合你。您可以尝试切换到常规的< cfinput type =text... 输入,并将您的面具更改为类似99/99 / 9999。这将给你正确的格式,但用户仍然可以输入无效的日期,所以你需要额外的代码来捕捉。



这只是另一个例子为什么使用内置-in ColdFusion UI标签不是一个好主意。他们工作非常简单的例子,但是当你需要更多的定制他们失败了你。你最好使用JavaScript库(如jQuery)来进行客户端验证。 Adobe自己的 Ben Forta已确认这几年前。并且 ColdFusion-UI-the-Right-Way项目已启动,因为



在另一个已发布的问题上Adam指出 ColdFusion文档中的另一个参考资料,强调了我的观点。 输入数据



在HTML和Flash表单中,mask属性控制可以输入到文本字段或在日期字段中选择的数据格式输入控制日历。 在HTML格式中,它不会阻止用户在日期字段输入控件中输入不遵循掩码的日期。 您可以对字段合并掩蔽和验证。 / p>


This is very frustrating. I am using cfinput datefield and mask="MM/DD/YYYY" and its not working. If it is cfinput text and mask="MM/DD/YYYY" it works perfect. I do not want to only have a textbox though I would like to keep the calendar that the date field gives you... The issue is when they use the calendar it is in the correct format MM/DD/YYYY but if the user just types in the date into the textbox without using the calendar the user can type whatever they desire.. (122334435) which obviously is unacceptable. Any ideas or workarounds anyone may be aware of?

Works:

    <cfform name="foo">
    <cfinput 
      type="text" 
      name="test" 
      validate="eurodate" 
      mask="99/99/9999" 
      validateat="onblur" />
    <input type="submit">
    </cfform>

Does Not Work:

    <cfform name="foo">
    <cfinput 
      type="datefield" 
      name="test" 
      validate="eurodate" 
      mask="MM/DD/YYYY" 
      validateat="onblur" />
    <input type="submit">
    </cfform> 

解决方案

I have added an answer to the other question that was originally opened regarding this same issue. I will post a bit here as well since users may find this question and not the other one. Or you could delete this question.

I believe the problem is that the mask attribute on the <cfinput type="datefield" ... code only works when using Flash forms - documentation reference.

I have emphasized the text from that documentation below:

Masking cfcalendar and datefield input

In the cfcalendar tag and the Flash format datefield input control, you use the following masks to determine the format of the output. You can use uppercase or lowercase characters in the mask:

...

The following pattern specifies that the Flash form sends the date selected using a datefield input control to ColdFusion as text in the format 04/29/2004:

<cfinput name="startDate" type="datefield" label="date:" mask="mm/dd/yyyy"/>

Since you are not using a Flash form the mask is not working for you. You could try switching to a regular <cfinput type="text" ... input and change your mask to something like "99/99/9999". That would give you the correct format but the user could still enter invalid dates so you would need additional code to catch that.

This is just another example of why using the built-in ColdFusion UI tags is not a good idea. They work for very simple examples but when you need more customization they fail you. You would be better off to use a JavaScript library (like jQuery) for client side validation. Adobe's own Ben Forta acknowledged this several years ago. And the ColdFusion-UI-the-Right-Way project was started because of this as well.

EDIT

On the other question that was posted Adam pointed out another reference in the ColdFusion documentation that reinforces my point. I have emphasized the text from that documentation below:

Masking input data

In HTML and Flash forms, the mask attribute controls the format of data that can be entered into a text field or that is selected in a datefield input control calendar. In HTML format, it does not prevent users from typing a date that does not follow the mask into a datefield input control. You can combine masking and validation on a field.

这篇关于日期字段掩码不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆