Need DatePicker, this code is not working
- frocco
- Member | 46
Hello,
I downloaded the datepicker and installed, but it is not working for me.
no calendar pops up for input field.
public function createComponentAppointmentForm() {
$form = new UI\Form;
\Vodacek\Forms\Controls\DateInput::register();
$form->addText('dob', 'Date of Birth:')
{control appointmentForm}
<script type="text/javascript" n:syntax="off">
$(document).ready(function() {
$('input[data-dateinput-type]').dateinput({
datetime: {
dateFormat: 'd.m.yy',
timeFormat: 'H:mm',
options: { // options for type=datetime
changeYear: true
}
},
'datetime-local': {
dateFormat: 'd.m.yy',
timeFormat: 'H:mm'
},
date: {
dateFormat: 'd.m.yy'
},
month: {
dateFormat: 'MM yy'
},
week: {
dateFormat: "w. 'week of' yy"
},
time: {
timeFormat: 'H:mm'
},
options: { // global options
closeText: "Close"
}
});
});
</script>
- frocco
- Member | 46
Thanks, I added lines below.
But still not working.
Do I have to change $(‘input[data-dateinput-type]’).dateinput({ to match
each field?
<script type='text/javascript' src="/nette-massage/www/scripts/jquery-ui-timepicker-addon.js"></script>
<script type='text/javascript' src="/nette-massage/www/js/dateInput.js"></script>
<link rel="stylesheet" type="text/css" href="/nette-massage/www/styles/jquery-ui-timepicker-addon.css">
<link rel="stylesheet" type="text/css" href="/nette-massage/www/css/datepicker.css">
- frocco
- Member | 46
Sorry your losing patience with me.
I did not see any manual at https://componette.org/search/?…
I guess nette is not for me if I cannot ask questions.
- tpr
- Member | 55
Sorry, that was no offense. I thought the smiley made that clear :)
The addon page clearly says that you need to include several files you haven't (according what you wrote):
`JS dependencies
- jQuery a jQueryUI
- Timepicker addon version 1.1.0 or newer`
So you need
- jQuery
- jQuery UI
- jquery-ui-timepicker-addon
- dateInput.js
Plus the css files:
- jquery-ui-timepicker-addon.css
- dateInput.css
I agree that starting with Nette can be hard. In fact I'm also learning it, creating my second project.
Last edited by tpr (2015-03-28 20:07)
- frocco
- Member | 46
Ok, I think I have everything loaded.
I have a field named dob.
How do I tell nette to use this datepicker?
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type='text/javascript' src="/nette-massage/www/scripts/jquery-ui/jquery-ui.js"></script>
<script type='text/javascript' src="/nette-massage/www/scripts/jquery-ui-timepicker-addon.js"></script>
<script type='text/javascript' src="/nette-massage/www/scripts/dateInput.js"></script>
<link rel="stylesheet" type="text/css" href="/nette-massage/www/styles/jquery-ui-timepicker-addon.css">
<link rel="stylesheet" type="text/css" href="/nette-massage/www/styles/dateInput.css">
<link rel="stylesheet" type="text/css" href="/nette-massage/www/scripts/jquery-ui/jquery-ui.css">
- tpr
- Member | 55
For example, add this to your form:
$form->addDate('date_booking', 'Booking date:', DateInput::TYPE_DATE);
Looks like the demo page is down, there were some examples (see the link in
the right sidebar of the addon page):
http://date-input.vodacek.eu/
- tpr
- Member | 55
You need to register DateInput in your bootstrap.php (as the addon page
says), and not in your presenter.
Make sure to add the ::register line BEFORE the createContainer line.
If Nette doesn't find something it means you haven't told it where to find
that.
Add DateInput to the “use” list (in the top of your presenter):
`use Nette,
App\Model,
// …
Vodacek\Forms\Controls\DateInput,
// Nette\Utils\DateTime,
// …
// Nette\Application\UI\Form;
Last edited by tpr (2015-03-28 21:12)
- tpr
- Member | 55
Glad you sorted it out.
Yes, you can use something like this:
$endDate = new DateTime('+1 years');
$endDate = $endDate->format('Y-m-d');
$form->addDate('date_booking', 'Foglalás dátuma:', DateInput::TYPE_DATE);
// ...
// ->addRule(Form::RANGE, 'Please add date between %d and %d', array($startDate, $endDate));
- frocco
- Member | 46
Thanks again,
Adding the rule causes this error.
->addRule($form::RANGE, 'Please add date between %d and %d', [$startDate, $endDate]);
Argument 1 passed to Vodacek\Forms\Controls\DateInput::normalizeDate() must be an instance of DateTime, string given, called in /Library/WebServer/Documents/nette-massage/vendor/voda/date-input/src/DateInput.php on line 138 and defined
I found out I need to remove the date->format function.
Last edited by frocco (2015-03-29 13:46)