2
0
forked from Wavyzz/dolibarr

Fix: Option COMPANY_USE_SEARCH_TO_SELECT was not working for third party

selection when autocomplete is on.
This commit is contained in:
Laurent Destailleur
2013-01-29 15:22:07 +01:00
parent a268592b61
commit 180fb2c91a
3 changed files with 24 additions and 4 deletions

View File

@@ -688,8 +688,21 @@ class Form
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{ {
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
$out.= ajax_combobox($htmlname, $event); /*
if ($selected && empty($selected_input_value))
{
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$product = new Product($this->db);
$product->fetch($selected);
$selected_input_value=$product->ref;
}
// mode=1 means customers products
$ajaxoptions=array();
$urloption='htmlname='.$htmlname.'&outjson=1&filter='.urlencode($filter).'&showtype='.$showtype;
$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
$out.='<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />';
*/
} }
$out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'; $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';

View File

@@ -771,7 +771,11 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
*/ */
(function( $ ) { (function( $ ) {
$.widget( "ui.combobox", { $.widget( "ui.combobox", {
options: {
minLengthToAutocomplete: 0,
},
_create: function() { _create: function() {
var savMinLengthToAutocomplete = this.options.minLengthToAutocomplete;
var self = this, var self = this,
select = this.element.hide(), select = this.element.hide(),
selected = select.children( ":selected" ), selected = select.children( ":selected" ),
@@ -781,7 +785,7 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
.val( value ) .val( value )
.autocomplete({ .autocomplete({
delay: 0, delay: 0,
minLength: 0, minLength: this.options.minLengthToAutocomplete,
source: function( request, response ) { source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( select.children( "option" ).map(function() { response( select.children( "option" ).map(function() {
@@ -854,7 +858,9 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
} }
// pass empty string as value to search for, displaying all results // pass empty string as value to search for, displaying all results
input.autocomplete({ minLength: 0 });
input.autocomplete( "search", "" ); input.autocomplete( "search", "" );
input.autocomplete({ minLength: savMinLengthToAutocomplete });
input.focus(); input.focus();
}); });
}, },

View File

@@ -303,11 +303,12 @@ function ajax_dialog($title,$message,$w=350,$h=150)
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @return string Return html string to convert a select field into a combo * @return string Return html string to convert a select field into a combo
*/ */
function ajax_combobox($htmlname, $event=array()) function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0)
{ {
$msg = '<script type="text/javascript"> $msg = '<script type="text/javascript">
$(function() { $(function() {
$("#'.$htmlname.'").combobox({ $("#'.$htmlname.'").combobox({
minLengthToAutocomplete : '.$minLengthToAutocomplete.',
selected : function(event,ui) { selected : function(event,ui) {
var obj = '.json_encode($event).'; var obj = '.json_encode($event).';
$.each(obj, function(key,values) { $.each(obj, function(key,values) {