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) »
  • Trouble with date fields using jcalendar.tpl
Pages: [1]

Author Topic: Trouble with date fields using jcalendar.tpl  (Read 922 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
Trouble with date fields using jcalendar.tpl
September 30, 2012, 02:22:14 pm
I am trying to add custom fields to a profile template by assigning them to the form in civicrm_buildForm, adding them to the template using $beginHookFormElements, and editing a custom copy of the template. I am doing it this way  because the custom fields are multiple record fields so they can not be added using the administration profile screens.

It is working ok, except for date fields.

I see that the standard template handles dates by simply using this:
{include file="CRM/common/jcalendar.tpl" elementName=$n}

$n has been assigned earlier using {assign var=n value=$field.name}

When I look at the created html from the standard view of the custom field using firebug I see this:
Code: [Select]
<input id="custom_93_3" class="form-text required" type="text" value="09/20/2012" name="custom_93_3" endoffset="1" startoffset="1" timeformat="1" format="mm/dd/yy" style="display: none;">
<input id="custom_93_3_display" class="dateplugin dpDate hasDatepicker" type="text" autocomplete="off" name="custom_93_3_display">

When I include the jcalendar in my profile I get this:
Code: [Select]
<input id="custom_93_3" class="form-text required" type="text" value="2012-09-20 06:16:00" name="custom_93_3" endoffset="10" startoffset="10" format="mm/dd/yy" addtime="1">
<input id="custom_93_3_display" class="dateplugin dpDate hasDatepicker" type="text" autocomplete="off" name="custom_93_3_display">

The key difference is  style="display: none;"  in the first input field. Mine does not have it so I see a text field with the filled in date from the defaults,  followed by the calendar date picker that is empty. 

I assigned the date to the form using  this function:  addDateTime($name, $label, $required = FALSE, $attributes = NULL). I then added it to the $beginHookFormElements following examples by Donald Lobo. The other (non-date) fields I added work fine.

I am new to this and and need some help.
Thanks.
Jere

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Trouble with date fields using jcalendar.tpl
September 30, 2012, 07:08:22 pm

date fields are a bit special and we render them in a special way:

Code: [Select]
{include file="CRM/common/jcalendar.tpl" elementName=birth_date}

rather than just emitting the html. Can you customize your profile template and use the above syntax rather than using beginHook....

thanx


lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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: Trouble with date fields using jcalendar.tpl
October 01, 2012, 06:49:47 am
That got rid of the double display. It added a script that hides the custom_93_3 element. The date value is correct in the hidden element.  However, it did not display the date in the custom_93_3_display element. I stepped through the javascript in firebug. The last line it enters is:

var displayDateValue = cj.datepicker.parseDate( altDateFormat, dateValue );

It dies somewhere in package/jquery/jquery.min.js. Once it enters the jQuery file, the code is all munged together and difficult to follow. It never makes it to the next line:
displayDateValue = cj.datepicker.formatDate( date_format, displayDateValue );

 I will compare with the tab for the custom in the contact summary page (where it works) and try to see if I see anything different from what is happening in my profile page. If that doesn't work I guess I will try saving the jquery file to a copy and then separate all the lines so I can see what is happening.

If you know a better way to debug this, please let me know.

I searched the forum and found this message
http://forum.civicrm.org/index.php/topic,20598.msg107002.html#msg107002
where someone else was having difficulty with this line. I will ask he ever resolved his difficulty.

Thanks for helping me with this.

--update--

Oh, the contact summary tab for this custom group delivers the entire form from the server with ajax. Something else I need to learn, I guess.

The buildCustomData that creates the page uses a qfKey code. If I replicate this approach, can I just copy this key , or does it change. If it changes, how can I retrieve the current qfKey?

Jere
« Last Edit: October 01, 2012, 07:30:50 am by jere »

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Trouble with date fields using jcalendar.tpl
October 01, 2012, 09:40:55 am
qfkey might be in the $form parameter somewhere - dump it with var_dump or your favorite method.
But if you mean ajax keys I think those are separate and you need to use CRM_Core_key::get. Usually I just copy and paste similar code from somewhere.

You don't need to manually deal with the jquery.min.js file - the "min" means minified or minimal and is compressed on purpose. Just get the "regular" source from http://jquery.com/download/, just make sure to match the version.

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: Trouble with date fields using jcalendar.tpl
October 01, 2012, 02:04:46 pm
Thanks for your help. It saves me a lot of time.

Jere

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trouble with date fields using jcalendar.tpl

This forum was archived on 2017-11-26.