'max' => 50,
'cells' => false, // combo displayed as 2 <td></td> cells
'search' => array(), // sql field names to search
- // if _focus is not set on next field before combo_input call
- // set this to false to avoid deadlock via onblur handler
- 'next_focus' => (!isset($_POST['_focus']) ||
- (isset($_POST["_{$name}_button"]) && $_POST['_focus']==$name)) ? false : $_POST['_focus'],
'format' => null, // format functions for regular options
'disabled' => false, // FIX todo
'box_hint' => null // box/selectors hints; null = std see below
: _('Enter description fragment to search or * for all')) :'';
if ($selected_id == null) {
- $selected_id = get_post($name);
+ $selected_id = get_post($name, null);
}
$txt = get_post($search_box);
$rel = '';
$Ajax->activate('_page_body');
else
$Ajax->activate($name);
- set_focus($opts['next_focus']);
}
- if ($search_box && $opts['search_submit']) {
+ if ($search_box) {
// search related sql modifications
$rel = "rel='$search_box'"; // set relation to list
-
+ if ($opts['search_submit']) {
// if selected from list - set focus on next field
if (isset($_POST[$search_submit])) {
$Ajax->activate($name);
- set_focus($name);
}
if ($txt == '') {
if ($spec_option === false)
$opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
}
}
+ }
// sql completion
if (count($opts['where'])) {
$sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
$sql .= $limit;
// ------ make selector ----------
- $selector = '';
- $first_id = $first_opt = '';
+ $selector = $first_opt = '';
+ $first_id = false;
$found = false;
//if($name=='code_id') display_error($sql);
if($result = db_query($sql)) {
$descr = $opts['format']==null ? $contact_row[1] :
call_user_func($opts['format'], $contact_row);
$sel = '';
- if (isset($_POST[$search_submit])) {
- if (($by_id ? $value : $contact_row[1]) === $txt)
- $selected_id = $value;
- }
- // if no initial selection - set the first item
- if ($selected_id === "") {
- $selected_id = $value;
- }
- if ($selected_id == $value) {
+ if ($selected_id === $value) {
$sel = 'selected';
$found = $value;
- $_POST[$name] = $selected_id;
}
- if ($first_opt == false) {
+ if ($first_id === false) {
$first_id = $value;
$first_opt = $descr;
- continue;
}
$selector .= "<option $sel value='$value'>$descr</option>\n";
}
db_free_result($result);
}
- // add first option - selected also if no match for selected_id was found
- // and no special option defined
- $sel = $spec_option===false || $found === $first_id ? 'selected' : '';
- $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
- . $selector;
-
// Prepend special option.
if ($spec_option !== false) { // if special option used - add it
$first_id = $spec_id;
$first_opt = $spec_option;
- if (isset($_POST[$search_submit])) {
- if ($txt == '')
- $selected_id = $spec_id;
- }
$sel = $found===false ? 'selected' : '';
$selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
. $selector;
}
if ($found === false) {
- $_POST[$name] = $first_id;
+ $_POST[$name] = $first_id;
}
-
if ($by_id) {
- $txt = $_POST[$name];
- if ($search_box)
- $Ajax->addUpdate($name, $search_box, $txt);
+ $txt = $_POST[$name];
+ if ($search_box)
+ $Ajax->addUpdate($name, $search_box, $txt);
}
$selector = "<select name='$name' class='$class' title='"
- . $opts['sel_hint']."' $rel>".$selector."</select>\n";
+ . $opts['sel_hint']."' $rel>".$selector."</select>\n";
$Ajax->addUpdate($name, "_{$name}_sel", $selector);
}
// ------ make combo ----------
-$edit_entry = '';
+ $edit_entry = '';
if ($search_box != false) {
$edit_entry = "<input type='text' name='$search_box' id='$search_box' size='".
$opts['size']."' maxlength='".$opts['max'].
- "' value='$txt' class='$class' rel='$name' title='"
+ "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
.$opts['box_hint']."'"
.(in_ajax() && !$by_id ? " style=display:none;":'')
.">\n";
-// default_focus($search_box);
if ($search_submit != false) {
global $_search_button;
$edit_entry .= sprintf($_search_button, user_theme(),
function stock_purchasable_items_list($name, $selected_id, $all_option=false,
$submit_on_change=false, $opts=array())
{
-
+ global $all_items;
$sql = "SELECT stock_id, s.description, c.description
FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c
WHERE s.category_id=c.category_id
'format' => '_format_account' . ($show_group ? '2' : ''),
'order' => 'account_code',
'search_box' => $cells,
- 'search_submit' => true,
+ 'search_submit' => false,
'size' => 12,
'max' => 10,
'cells' => true