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) »
  • Setting defaults on Autocomplete field
Pages: [1]

Author Topic: Setting defaults on Autocomplete field  (Read 623 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Setting defaults on Autocomplete field
July 19, 2011, 07:02:01 am
How do I set the default on an autocomplete field

if I do this

Code: [Select]
#
$defaults['custom_47_-1'] = $contact_id;
#
        $form->setDefaults($defaults);

Then the form loads with a number in the autocomplete field & doesn't resolve it
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Setting defaults on Autocomplete field
July 19, 2011, 10:11:48 am
I seem to recall setting the default for a select widget to the exposed label text rather than the value associated with it. You may need to use the display_name rather than the contact_id. Just a guess.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Setting defaults on Autocomplete field
July 24, 2011, 01:29:02 am
Hi,

I add

Code: [Select]
        $defaults['custom_127_-1'] = civicrm_api('contact','getvalue',array('version' => 3,
        'id' => $pledge['custom_129'],
        'return' => 'display_name'));

& the default shows as display name when I load the form but when I go to save:

Quote
Please correct the following errors in the form fields below:

    * Select a valid contact for Worker Contact.

So I guess that's not it....
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Setting defaults on Autocomplete field
July 25, 2011, 03:30:32 am
Try:

Quote
$defaults['custom_47_-1_id'] = $contact_id;
$defaults['custom_47_-1'] = $display_name;
$form->setDefaults($defaults);

Kurund
Found this reply helpful? Support CiviCRM

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

This forum was archived on 2017-11-26.