meeting-room-booking-system / mrbs-code

MRBS application code
Other
120 stars 58 forks source link

Custom Field and View Entry #1783

Open jberanek opened 7 years ago

jberanek commented 7 years ago

Hi.. i have added custom field using $select_option for eg: $select_options['entry.dept_llm'] = array('' => 'Sila Pilih Bahagian', '1' => 'Pengurusan LLM', '2' => 'Khidmat Pakar & Kerjasama Teknikal', '3' => 'Mekanikal & Elektrikal', '4' => 'Kewangan & Pengurusan Aset', '5' => 'Teknologi Maklumat', '6' => 'Pemantauan Operasi', '7' => 'Pengawasan Tol', '8' => 'Pengurusan Projek', '9' => 'Pengurusan Rekabentuk', '10' => 'Pengurusan Tanah', '11' => 'Perancangan', '12' => 'Sumber Manusia & Pentadbiran', '13' => 'Ukur Bahan & Kontrak', '14' => 'Unit Audit Dalam', '15' => 'Undang-Undang', '16' => 'Pejabat Wilayah Tengah');

$is_mandatory_field['entry.dept_llm'] = true;

it works and the key such as '16' inserted into the database.

But my question is can I show the value 'Pejabat Wilayah Tengah' instead of view '16' in view entry, email notification and reports?..

p/s : my type of dept_llm is INTEGER

Reported by: *anonymous

Original Ticket: mrbs/support-requests/1062

jberanek commented 7 years ago

Hmm, it does look like that configuration should work, but it doesn't work for me either...so, it could be a bug.

Original comment by: jberanek

jberanek commented 7 years ago

Actually, it seems that having $select_options with an associative array only works if the keys are characters/strings, and not numbers. I seem to remember this is because PHP is unable to tell the difference between an associative array with numeric keys and a plain indexed array. The MRBS code checks that the $select_options array is an associative array, and if the key is a number, this fails.

Original comment by: jberanek

jberanek commented 7 years ago

Indeed, if the custom field is a CHAR(4) I can do the following successfully:

$select_options['entry.selectfield'] =
  array("a" => "foo",
        "b" => "blah",
        "c" => "blah2");

Original comment by: jberanek

jberanek commented 7 years ago

Dear John,

Thanks for your prompt response.

i have add as per below :

edit_entry.php

function create_field_entry_custom_field($field, $key, $disabled=FALSE) { global $custom_fields, $tbl_entry; global $is_mandatory_field, $text_input_max, $maxlength;

echo "

\n"; $params = array('label' => get_loc_field_name($tbl_entry, $key) . " :", 'name' => VAR_PREFIX . $key, 'value' => isset($custom_fields[$key]) ? $custom_fields[$key] : NULL, 'disabled' => $disabled, 'attributes' => array(), 'force_assoc' => TRUE, <------added---> 'maxlength' => isset($maxlength["entry.$key"]) ? $maxlength["entry.$key"] : NULL, 'mandatory' => isset($is_mandatory_field["entry.$key"]) && $is_mandatory_field["entry.$key"]);

// Output a checkbox if it's a boolean or integer <= 2 bytes (which we will // assume are intended to be booleans) if (($field['nature'] == 'boolean') || (($field['nature'] == 'integer') && isset($field['length']) && ($field['length'] <= 2)) ) { generate_checkbox($params); } // Output a textarea if it's a character string longer than the limit for a // text input elseif (($field['nature'] == 'character') && isset($field['length']) && ($field['length'] > $text_input_max)) { // HTML5 does not allow a pattern attribute for the textarea element $params['attributes'][] = 'rows="8"'; $params['attributes'][] = 'cols="40"'; generate_textarea($params);
} // Otherwise output an input else { $is_integer_field = ($field['nature'] == 'integer') && ($field['length'] > 2); if ($is_integer_field) { $params['type'] = 'number'; $params['step'] = '1'; } else { $params['type'] = 'text'; if ($params['mandatory']) { // 'required' is not sufficient for strings, because we also want to make sure // that the string contains at least one non-whitespace character $params['pattern'] = REGEX_TEXT_POS; } } $params['field'] = "entry.$key"; generate_input($params); } echo "

\n"; }

i have added those function to make the $select_option insert the int type to database.

if i change the type of dept_llm to varchar, it will create a html textarea instead of dropdown list.

Any suggestion?.

Original comment by: *anonymous

jberanek commented 7 years ago

Never mind Mr. John. I have change the table type to varchar as your suggested. It works. Hooreyyyyyy!!!

Original comment by: *anonymous

jberanek commented 7 years ago

If the length of the varchar is greater than the config setting $text_input_max (default 70) then you get a textarea rather than an ordinary input or select.

Original comment by: campbell-m

jberanek commented 7 years ago

Thanks Mr. Campbell for your explaination. It works for me now by using varchar(40). And thank you for provide the world the best open source meeting room booking system

Original comment by: *anonymous