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) »
  • default state via hook
Pages: [1]

Author Topic: default state via hook  (Read 906 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
default state via hook
October 31, 2010, 08:37:17 pm
Hi,

I want to set the default state for an installation. I can't do it across the board but was able to do it in new individual using the buildform hook

 if ($form->_defaultValues['address'][1]['country_id']){
       $defaults['address'][1]['state_province_id'] = 1018;
       $form->setDefaults($defaults);

 }

but no matter what I set it doesn't seem to listen to me on the contribution page



       $defaults['state_province_id-5'] = 1018;
       $defaults['state_province-5'] = 1018;
       $defaults['state_province-1'] = 1018;
       $defaults['billing_state_province_id-5'] = 1018;
       $form->setDefaults($defaults);

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: default state via hook
November 01, 2010, 02:24:23 am
Does state_province with id 1018 is part of your default country?

We are using JS to load states based on country selection. So might be possible something is resetting. So I think setting defaults using JS might be easier.

Kurund
Found this reply helpful? Support CiviCRM

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: default state via hook
November 01, 2010, 12:13:53 pm
Yes, that would make sense. Would I use custom tpl over-ride file in that case?
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

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: default state via hook
November 01, 2010, 12:42:41 pm
Seems like you could use tpl override, or use drupal_add_js() in the hook.

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: default state via hook
November 01, 2010, 12:43:40 pm
Hmm - that second sounds more appealing. Js isn't really my strong suit but maybe I should learn!
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

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: default state via hook
November 01, 2010, 12:53:07 pm
Civi uses jQuery, which has great online documentation.  Note that where jquery normally uses $.(), Civi's implementation of jQuery normally uses cj.(), but otherwise the docs at jquery.com will be your bestest-est friend.

BTW, something like this is decent for setting values field after the page has loaded:
Code: [Select]
cj().ready( function() {
    cj.('#id_of_your_form_element').val('foo');
})

Tricky part is whether civi is probably calling the state list via ajax, in which you have to somehow wait until after that fires before you can set the value on the state field.  In that case you might have to find the JS code that makes that AJAX call and insert your state-setting code after that.  Not sure where that code is -- maybe in the template?

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

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

This forum was archived on 2017-11-26.