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) »
  • CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
Pages: [1]

Author Topic: CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem  (Read 3493 times)

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
January 08, 2009, 01:46:01 am
Hello:

   I tried the the api snippet on a CiviCRM 2.1.4 / Drupal 6 installation.
http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Data+Group+and+Custom+Field+APIs

$customGroup = $this->customGroupCreate('Contact', 'Radio_test_group');
$params      = array (
                      'custom_group_id' => $customGroup['id'],
                      'label'           => 'PriceRadio',
                      'html_type'       => 'Radio',
                      'data_type'       => 'String',
                      'weight'          => 4,
                      'is_required'     => 1,
                      'is_searchable'   => 0,
                      'is_active'       => 1,
                      'option_label'    => array( 'radioLabel1','radioLabel2'),
                      'option_value'    => array( 10, 20 ),
                      'option_weight'   => array( 1, 2),
                      );

$customField =& civicrm_custom_field_create($params);

This does create the Radio Button but the options are Inactive by default. Is this a bug ? because when one creates a Custom Field with multiple options by default each option is Active.

Thanks.

Yashesh Bhatia.

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
January 08, 2009, 04:22:17 am
Fixed. I had to add the option_status as follows.
$params      = array (
                      'custom_group_id' => $customGroup['id'],
                      'label'           => 'PriceRadio',
                      'html_type'       => 'Radio',
                      'data_type'       => 'String',
                      'weight'          => 4,
                      'is_required'     => 1,
                      'is_searchable'   => 0,
                      'is_active'       => 1,
                      'option_label'    => array( 'radioLabel1','radioLabel2'),
                      'option_value'    => array( 10, 20 ),
                      'option_weight'   => array( 1, 2),
                      'option_status'   => array( 1, 0),
                      );

best.

yashesh

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
January 08, 2009, 05:40:25 am
or maybe the code should be changed to make it default to active
in the file - civicrm/CRM/Core/BAO/CustomField.php:173:

$optionValue->is_active       =  CRM_Utils_Array::value( $k, $params['option_status'], false );

should be changed to

$optionValue->is_active       =  CRM_Utils_Array::value( $k, $params['option_status'], true );

yashesh

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: CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
January 08, 2009, 08:13:30 am

i dont think the below is right code wise, since radio buttons / checkboxes dont POST their values if they are unchecked. Hence the default needs to be false

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

yasheshb

  • I post occasionally
  • **
  • Posts: 72
  • Karma: 5
Re: CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem
January 08, 2009, 10:20:00 pm
agreed. since the BAO calls are used by the ui and api. We can fix the

api/v2/CustomGroup.php at around line number 190 to ensure we have true for all option status unless explicitly stated by
the option_status array to be 'false'.

    require_once 'CRM/Core/BAO/CustomField.php';
    $customField = CRM_Core_BAO_CustomField::create($params); 

also, i've made a note on the wiki  - http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Data+Group+and+Custom+Field+APIs?focusedCommentId=12189697&#comment-12189697

thx.

yashesh

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • CiviCRM 2.1.4-Drupal 6. Creating custom fields with multi value options problem

This forum was archived on 2017-11-26.