Solved

CFINPUT TYPE=DATEFIELD Question

Posted on 2010-09-13
13
790 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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