CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • date defaults and jCalendar
Pages: [1]

Author Topic: date defaults and jCalendar  (Read 2599 times)

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
date defaults and jCalendar
June 28, 2013, 03:13:49 pm
UPDATE: Nevermind, I see how I can use an api rather than recalling the profile using window.location. In cases like this, I am not sure of the proper protocol for the forum -- remove the post,  leave the post with an update like I am doing here, or add a reply with an update.

I am having difficulty with dates using jCalendar for dates.

When I try to set the default for a date field in the buildForm hook I get the following error in the Firebug console: uncaught exception: Unexpected literal at position 2.

If I don't use jCalendar (which results in a text box for the date) the default that was set is in the text box.

Any ideas about why? Do I need a specific format for the date?

I am using just a date field and not using datetime. Thus in the following $form->addDate there is no 'timeFormat' field.

Here are the code I used for setting the element in the form showing what I think are relevant lines:
Code: [Select]

$after = CRM_Utils_Request::retrieve('after', 'String');
$defaults['after_start_date'] = $after;
...
$form->addDate("after_start_date", 'Return events starting after : ', FALSE, array(
          'format' => 'mm-dd-yy',
          'startOffset' => 5,
          'endOffset' => 5,
  ));
...

$form->setDefaults($defaults);

I am using "window.location" after I capture the filter selections the user makes instead of posting the results. That is, I am sending the date as a query in the url back to the same profile to find a different result set for the same profile.

If I just leave the date field blank that the user has just used to select the new result set it works fine.
« Last Edit: June 30, 2013, 01:37:56 pm by jere »

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: date defaults and jCalendar
June 30, 2013, 04:43:43 pm
Adding your solution to the bottom of your post or adding a reply with a solution is a good idea--that way if someone else has the same problem, he can find a solution also. :)
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

jere

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 1
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.31
  • PHP version: 5.3.10
Re: date defaults and jCalendar
July 12, 2013, 06:55:53 am
This is a followup to explain what I ended up doing.

As a short background, I had a profile with filter questions at the top and a form and related output at the bottom that was created based on the filters entered by the user.

The form originally worked by using  "window.location" to return to the same profile with new filter data. The filters were being passed as queries in the url and retrieved in a hook using CRM_Utils_Request::retrieve() which recreated the elements and defaults used by the smarty template. The form was originally created a while ago but date filters were wanted as fields in the filter. I was having trouble getting the date field data to work while sending them back to the server in the url to be retrieved.

I stopped using the "window.location" and switched to using javascript and CRM.api calls. I took the layout of the template from the profile template (.tpl file) and included an empty copy of the bottom part to be recreated based on the filters. It was included as a hidden section of the form. In the success function of the api I filled in the appropriate places with the data. I then displayed the filled section. On subsequent submissions of the filter the data changes in place without refreshing the page.

The problem with the date field went away since the filters at the top of the page were not affected by the CRM.api calls. It also works more quickly and is more user friendly.



Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • date defaults and jCalendar

This forum was archived on 2017-11-26.