I was trying to execute some javascript when a date was picked and found this post when looking for an answer. So, here's what I did to get it to work.
I duplicated the Datetime Sugarfield so I could make a change and it would be upgrade safe.
Copy the contents of include/SugarFields/Datetime to a new folder.
Example include/SugarFields/Datetimecustom
Rename SugarFieldDatetime.php to SugarFieldDatetimecustom.php
Edit it and change the class name from SugarFieldDatetime to SugarFieldDatetimecustom and the last line:
return $this->fetch('include/SugarFields/Fields/Datetime/EditView.tpl');
to
return $this->fetch('include/SugarFields/Fields/Datetimecustom/EditView.tpl');
If you'll look at jssource/src_files/jscalendar/calendar-setup_3.
js, you will see the available config parameters. The one I was interested in was onUpdate.
So, edit EditView.tpl and add the onUpdate parameter to the calendar setup and give it the function of your choosing.
Example:
<script type="text/javascript" language="javascript">
Calendar.setup ({ldelim}
inputField : "{{sugarvar key='name'}}",
daFormat : "{$CALENDAR_FORMAT}",
button : "{{sugarvar key='name'}}_trigger",
singleClick : true,
dateStr : "{$date_value}",
step : 1,
onUpdate : calUpdate
{rdelim}
);
</script>
Now you will need to define a javascript function called calUpdate and include it in the view.
And lastly, you will need to edit the editviewdefs.php and add a type def to point to the newly defined SugarField.
Example
array (
'name' => 'my_date',
'label' => 'LBL_MY_DATE',
'type' => 'Datetimecustom',
),
You will then need to do do a rebuild/repair to update the cache and then when a date is selected using the datepicker, it will call your javascript callback.
Hope this helps.
Steve
Bookmarks