Solved

CFINPUT TYPE=DATEFIELD Question

Posted on 2010-09-13
13
787 Views
Last Modified: 2013-12-24
Hi,
I am using the pop up date field provided by CF by using the Type="datefield" :

<cfinput name="toDate" type="datefield" class="inputboxShort"  required="no" size="40" maxlength="10"  readonly="readonly" />

I'd like to open the field up for input and provide only my own server side edit of the field BUT CF seems to have an implied option of validate="date" (makes sense I guess).  Is there a way to override that?  I'd  like to control the display of my own error message on the page.

Could I use a validate= regex that accepts anything or nothing?  What is that regex?

I think I'll need to keep it read only?

Thanks in advance,
hefterr
0
Comment
Question by:hefterr
  • 6
  • 5
  • 2
13 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 33664268
>> seems to have an implied option of validate="date"

Are you sure? I did a quick test and didn't any problem entering a non-date like "ABC" in the box.

<cfform method="post">
      <cfinput name="toDate" type="datefield"
                  required="yes" size="40" maxlength="10" />
      <input type="submit">
</cfform>
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33664366
I am not sure you need validation. Just make the field read only so the user can not update the date and in this case forget about validation
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33664504
Yeah, I'd agree.  Though I'm not sure it even does validation in the first place ...
0
 
LVL 1

Author Comment

by:hefterr
ID: 33664552
Hi agx,
I'm not sure what I'm doing differently - But I'm getting the error message page (see attached).

Maybe something on my server side code when I process the form.
Datefield.doc
0
 
LVL 1

Author Comment

by:hefterr
ID: 33664658
agx,
It as if I took you code and added a value statement :

<cfform method="post">
      <cfinput name="toDate" type="datefield"
                  required="no" size="40" maxlength="10"  value="mm/dd/yyyy" />
      <input type="submit">

You would get the same error.

hefterr
0
 
LVL 1

Author Comment

by:hefterr
ID: 33664735
OK guys, I found the problem.

I tried using in the CFFORM tag, Preservedata="yes".  This is causing the problem.  When I take it out it's OK.  I tried using it as a short cut to redisplay the data on an error - but it causes a problem in this case.

I guess it's back to the drawing board.  I'll have to repopulate manually the input date fields on an error.

Thanks,
hefterr
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:hefterr
ID: 33664888
folks,
.... and you cannot give an invalid "value = " to the CFINPUT statement.

That was my ORIGINAL question to begin with.  Soooooo, any suggestions?

hefterr
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33664898
just make todays date as a default
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33664940
Yeah, unfortunately preserveData has ... limitations. If you supply a "value" (or if preserveData  does), CF will validate that "value" on the server side.  So if you want to use preservedata you'll have to manually handle that field.  

Try deleting that key if it is NOT a date.

<cfparam name="form.toDate">
<cfform method="post" Preservedata="yes">
      <cfif NOT isDate(FORM.toDate)>
            <cfset structDelete(FORM, "toDate")>
      </cfif>
      <cfinput name="toDate" type="datefield"
                        required="yes" size="40" maxlength="10"
                         />
      <input type="submit">
</cfform>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33664948
Correction:

<cfparam name="form.toDate" default="">
<cfform method="post" Preservedata="yes">
      <cfif NOT isDate(FORM.toDate)>
            <cfset structDelete(FORM, "toDate")>
      </cfif>
      <cfinput name="toDate" type="datefield" size="40" maxlength="10" />
      <input type="submit">
</cfform>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 33665026
>> and you cannot give an invalid "value = " to the CFINPUT statement.

Yeah, I see the only way you can pass an invalid value to the CFINPUT is with javascript - ie after the fact. You can't do it using "value"

      <script>
            document.getElementById('toDate').value = 'blah blah. something invalid';
      </script>
0
 
LVL 1

Author Comment

by:hefterr
ID: 33665411
Hi agx,
One last question.  Where exactly would I put this Javascript statement if I removed Preservedata?

Thanks again for you expertise!!
hefterr
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33665567
I'd put it in a function (for clarity) then call it onLoad

ie
<body onLoad="yourFunction()">

0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now