Solved

CFINPUT TYPE=DATEFIELD Question

Posted on 2010-09-13
13
788 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
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

10 Experts available now in Live!

Get 1:1 Help Now