0

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> 
  • 3
    Isn't this a duplicate question? http://stackoverflow.com/q/26286518/1636917. As I said before, the `datefield` type is specific to Flash forms. That is why it does not work for you. – Miguel-F Oct 14 '14 at 20:22
  • Do you see an answer to fix it? –  Oct 14 '14 at 20:24
  • 2
    It can't be fixed. It is only for Flash forms. – Miguel-F Oct 14 '14 at 20:24
  • Datefields? Why does it work everything but Mask then? –  Oct 14 '14 at 20:25
  • You think there isn't anyway around that? No JavaScript Jquery Nothing? –  Oct 14 '14 at 20:25
  • 1
    Of course you can use JavaScript / jQuery but that has nothing to do with cfinput. This is just another example of the poor implementation of the cfxxx form tags and why you should not use them. Absolutely use jQuery. – Miguel-F Oct 14 '14 at 20:27
  • I am really starting to dislike CF –  Oct 14 '14 at 20:28
  • 2
    @Bauer you should learn to write JavaScript yourself rather than relying on a crap implementation built into the language. I'm not aware of any other language that has the UI bloat built in. If that's why you dislike CF you won't like any language. – Matt Busche Oct 14 '14 at 20:46
  • There are dozens of jQuery plug-ins that will help you do exactly what you're trying to accomplish – Matt Busche Oct 14 '14 at 20:52
  • To back up Matt's point: http://www.raymondcamden.com/2014/1/23/Im-not-going-to-tell-you-to-stop-using-ColdFusion-UI-tags-anymore – Blaise Swanwick Oct 14 '14 at 20:53
  • hahaha yes I do need to learn it... it seems like everything evolves around javascript or jquery. Seems to be very handy if you understand it. –  Oct 14 '14 at 20:53
  • 4
    I understand your frustration. We have all been there. You start out using those cfxxx tags and think wow that was easy. But as soon as you need a little bit more complexity they stop being easy and in fact become more problematic. Definitely learn jQuery or the like and your pages will be better for it. You should find lots of examples out there. – Miguel-F Oct 14 '14 at 20:54
  • Is Jquery hard to set up? –  Oct 14 '14 at 20:54
  • Its just a download and you call it right? –  Oct 14 '14 at 20:55
  • Yep, you download it and include it and then it works. Pretty simple. – Matt Busche Oct 14 '14 at 20:58
  • any idea of which one to download? aren't there many with many add ons? –  Oct 14 '14 at 21:02
  • also should I end up deleting this question since there is no real answer to this? –  Oct 14 '14 at 21:03
  • lol or should I change it asking for a jquery script for it hahaha –  Oct 14 '14 at 21:04
  • Please do not open multiple threads for the *same* question. If you need to add more details, just "edit" the existing one ;-) This thread should be deleted because it is a duplicate of the other one. – Leigh Oct 14 '14 at 21:12
  • See [coldfusion ui the right way](https://github.com/cfjedimaster/ColdFusion-UI-the-Right-Way) to get you started. This is exactly why they started that project. Then when you have specific coding questions come back and ask. – Miguel-F Oct 14 '14 at 21:20
  • Doesn't eurodate use periods to separate the date components? – Dan Bracuk Oct 14 '14 at 21:50
  • 2
    I notice you are validating onblur. Bad idea. The user can clear the alert and submit the form anyway. Much better to validate onsubmit. – Dan Bracuk Oct 14 '14 at 22:47

1 Answers1

1

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.

Community
  • 1
  • 1
Miguel-F
  • 13,450
  • 6
  • 38
  • 63