Reputation: 414
I'm building a form that will insert to a mysql db in Codeigniter(3.0) and one of the fields is supposed to be a publish date. I'm new to CI but have used datepicker before and assumed it would just work.
From my template header file
<html>
<head>
<meta charset="utf-8">
<title>Add a new comic</title>
<link rel="stylesheet" href="http://foo.com/ci/css/newstyle.css" type="text/css" media="screen">
<link rel="stylesheet" href="http://foo.com/ci/css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$(function() {
$('#datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd');
});
});
</script>
</head>
From my form.php
<div id="upload">
<?php
echo form_open_multipart('comic/createComic');
echo form_upload('userfile');
echo form_input('comic_title', 'Comic Title');
echo form_input('title_text', 'Hover Test');
?>
<input type="text" id="datepicker" title="publish_date" name="publish_date" value="">
<?php
echo form_submit('upload', 'Upload');
echo form_close();
?>
</div>
From the controller
function createComic()
{
$this->load->model('Image_model');
if($this->input->post('upload'))
{
$this->Image_model->do_upload();
}
$data = array(
'comic_filename' => $this->upload->data('file_name'),
'comic_title' => $this->input->post('comic_title'),
'title_text' => $this->input->post('title_text'),
'publish_date' => $this->input->post('publish_date'),
);
$this->db->set('uploaded', 'NOW()', FALSE);
$this->site_model->add_comic($data);
$this->index();
}
I have an image model and a site model that simply run inserts that are working properly. I am getting a text field that I can manually enter a date into which formats in ISO and inserts without any problems.
The problem is that I get no UI datepicker to load at all. You have to enter the date manually.
What am I missing here? I'm sure there is some idiosyncrasy I don't know yet or I am making a simple mistake in syntax and any help is greatly appreciated.
Can't get a jQuery UI datepicker to load the graphical calendar to allow users to select a date in a form built on the Codeigniter platform. Please see code above and let me know where I am going wrong.
Upvotes: 1
Views: 1384
Reputation: 10533
The problem is with the options you are feeding into your initialisation of datepicker()
Try changing it to the below:
$(function() {
$('#datepicker').datepicker({
dateFormat: "yy-mm-dd"
});
});
The original format you were using if for setting options after the datepicker has been initialised.
$('#datepicker').datepicker( "option", "dateFormat", "yy-mm-dd" );
Upvotes: 1