I switched from select boxes to the jQuery datepicker with Cakephp 2.3.8 and I'm wondering if there's a way that I can trigger a POST request with the JS helper when the date is selected. I send POST request to look up values for that specific date. I know it can be done with just jQuery/AJAX, but if I can use the JS helper I'd prefer that since I already have it implemented from when I used the select boxes.
For example, the request will be triggered when the input is clicked, but not when a date is actually selected
$this->Js->get('#arrival_date')->event('click', //also tried change
$this->Js->request(array(
'controller'=>'registration',
'action'=>'room_number'
), array(
'update'=>'#RegistrationRoomId',
'async' => true,
'method' => 'post',
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => false,
'inline' => true
))
))
);
I know I can get it to work with something like this, but since I switched to the datepicker from just using select boxes for the date, I already have everything else implemented for the JS helper. The only issue is getting the JS helper to trigger when a value is selected.
jQuery(function($){
$(document).ready(function() {
$("input.datepicker").datepicker({
onSelect: function(date){
check_availability(date);
},
dateFormat: 'mm-dd-yy',
yearRange: "-100:+50",
changeMonth: true,
changeYear: true,
constrainInput: false,
showOn: 'both',
buttonImageOnly: true
});
});
});
function check_availability(date){
//do stuff here
}