Development

#493 (object_select_tag broken when using include_blank or include_custom and object has non-consecutive keys.)

You must first sign up to be able to contribute.

Ticket #493 (closed defect: fixed)

Opened 3 years ago

Last modified 1 year ago

object_select_tag broken when using include_blank or include_custom and object has non-consecutive keys.

Reported by: anonymous Assigned to: fabien
Priority: major Milestone:
Component: helpers Version:
Keywords: Cc:
Qualification: Unreviewed

Description

object_select_tag broken when using include_blank or include_custom and object has non-consecutive keys.

This is because include_blank and include_custom get array_unshifted onto the select_options array. This re-indexes select_options, thus changing its keys (which is supposed to represent object Ids.

I have written a function to fix this and some other problems:

function my_object_select_tag($object, $method, $options = array(), $default_value = null) {

$param_name = _convert_method_to_name($method, $options); if (($reqvalue = _get_request_value($param_name)) !== null && $default_value === null) {

$default_value = $reqvalue;

}

$options = _parse_attributes($options); $related_class = isset($optionsrelated_class?) ? $optionsrelated_class? : ; if (!isset($optionsrelated_class?) && preg_match('/get(.+?)Id$/', $method, $match)) {

$related_class = $match[1];

} unset($optionsrelated_class?);

$select_options = _get_values_for_object_select_tag($object, $related_class);

$merge_array = array(); if (isset($optionsinclude_merge?)) {

$merge_array= $optionsinclude_merge?; unset($optionsinclude_merge?);

}

if (isset($optionsinclude_custom?)) {

array_unshift($merge_array, $optionsinclude_custom?); unset($optionsinclude_custom?);

} else if (isset($optionsinclude_title?)) {

array_unshift($merge_array, '-- '._convert_method_to_name($method, $options).' --'); unset($optionsinclude_title?);

} else if (isset($optionsinclude_blank?)) {

array_unshift($merge_array, ); unset($optionsinclude_blank?);

}

// ksort($select_options,SORT_NUMERIC);

if (!empty($merge_array)) {

$select_options = $merge_array+ $select_options;

}

$value = _get_object_value($object, $method, $default_value); $option_tags = options_for_select($select_options, $value, $options);

return select_tag(_convert_method_to_name($method, $options), $option_tags, $options);

}

Change History

02/21/07 14:44:15 changed by francois

  • owner set to fabien.
  • component set to helpers.

06/25/07 10:04:26 changed by Rihad.Haciyev

I can't believe this...

05/07/08 10:32:49 changed by noel

  • status changed from new to closed.
  • resolution set to fixed.
  • qualification set to Unreviewed.

Fixed since r1028

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.