Solved

cfdiv jquery datepicker

Posted on 2014-12-15
12
86 Views
Last Modified: 2015-01-27
I have a main page that has a cfdiv that is bound to some filter inputs on the main page.

<input name="SelectDate" type="text" class="datestuff">

<cfdiv bind="url:divPages.cfm?SelectDate={SelectDate}" id="pageDiv" bindonload="true" />

Open in new window


The datepicker stuff works fine but the bind to the input element doesn't work.  I've tried @blur and @mouseout but the timing is off.  If I don't use datepicker, the bind works fine, but datepicker is the default for the site.  

The datepicker code is;
function initDateStuff() {
			$(function() {
				$('input.datestuff').datepicker({
					dateFormat: 'yy/mm/dd'
				});
			});
		}

Open in new window


And at the bottom of the cfdiv page I have;
<cfset ajaxOnLoad("initDateStuff")>

Open in new window

0
Comment
Question by:lanterv
  • 7
  • 5
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40502012
be sure to bind BEFORE setting the datepicker :
$('input.datestuff').on("click", function() { alert("first!"); });
$('input.datestuff').datepicker({....

Open in new window


and not :
$('input.datestuff').datepicker({...
$('input.datestuff').on("click", function() { alert("first!"); });

Open in new window

0
 

Author Comment

by:lanterv
ID: 40503426
I don't understand.  Where did " on.click" come from?  The datepicker doesn't work unless it's in the head.  Besides, CF generates the code for the bind and puts it where ever it wants.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40503451
OK so use a setTimeout to create your datepicker,
setTimeout(function() {
    $("input.datestuff").datepicker (...
}, 500); // 500ms before creating it
0
 

Author Comment

by:lanterv
ID: 40503667
setTimeout(function() {
    $('input.datestuff').datepicker (dateFormat: 'yy/mm/dd');
}, 500)

Open in new window


Give me a syntax error:

SyntaxError: missing ) after argument list
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40503763
you forgot the brackets...

setTimeout(function() {
    $('input.datestuff').datepicker ({dateFormat: 'yy/mm/dd'});
}, 500)

Open in new window

0
 

Author Comment

by:lanterv
ID: 40503786
That made the datepicker work.  But the cfdiv bind to the datefield doesn't work.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:lanterv
ID: 40503798
Using cfinput type="datefield" or input type="date" doesn't work either.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40504033
did you try mousedown instead mouseout?
0
 

Author Comment

by:lanterv
ID: 40504129
Yes I did. Doesn't work.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40504433
time to share a link to your website, a simple onclick work fine : http://jsfiddle.net/w4jmbgqm/1/
0
 

Author Comment

by:lanterv
ID: 40505480
It's an internal admin site.  Not public.  Sorry.  I'll see what I can do about creating it on a public site.
0
 

Author Closing Comment

by:lanterv
ID: 40573978
Thank you
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

8 Experts available now in Live!

Get 1:1 Help Now