[FIX] Changed search view for jquery ui upgrade (autoFocus doesn't seems to work)
bzr revid: fme@openerp.com-20121031173009-fxkz0ongj9b2v6f2
This commit is contained in:
parent
ca6c49becf
commit
903edfe306
|
@ -371,15 +371,6 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
||||||
self.$el.find('.oe_searchview_input:last').focus();
|
self.$el.find('.oe_searchview_input:last').focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// when the completion list opens/refreshes, automatically select the
|
|
||||||
// first completion item so if the user just hits [RETURN] or [TAB] it
|
|
||||||
// automatically selects it
|
|
||||||
this.$el.on('autocompleteopen', function () {
|
|
||||||
var menu = self.$el.data('autocomplete').menu;
|
|
||||||
menu.activate(
|
|
||||||
$.Event({ type: "mouseenter" }),
|
|
||||||
menu.element.children().first());
|
|
||||||
});
|
|
||||||
|
|
||||||
return $.when(p, this.ready);
|
return $.when(p, this.ready);
|
||||||
},
|
},
|
||||||
|
@ -429,58 +420,46 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
||||||
setup_global_completion: function () {
|
setup_global_completion: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// autocomplete only correctly handles being initialized on the actual
|
var autocomplete = this.$el.autocomplete({
|
||||||
// editable element (and only an element with a @value in 1.8 e.g.
|
|
||||||
// input or textarea), cheat by setting val() on $el
|
|
||||||
this.$el.on('keydown', function () {
|
|
||||||
// keydown is triggered *before* the element's value is set, so
|
|
||||||
// delay this. Pray that setTimeout are executed in FIFO (if they
|
|
||||||
// have the same delay) as autocomplete uses the exact same trick.
|
|
||||||
// FIXME: brittle as fuck
|
|
||||||
setTimeout(function () {
|
|
||||||
self.$el.val(self.currentInputValue());
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
this.$el.autocomplete({
|
|
||||||
source: this.proxy('complete_global_search'),
|
source: this.proxy('complete_global_search'),
|
||||||
select: this.proxy('select_completion'),
|
select: this.proxy('select_completion'),
|
||||||
focus: function (e) { e.preventDefault(); },
|
focus: function (e) { e.preventDefault(); },
|
||||||
html: true,
|
html: true,
|
||||||
|
autoFocus: true,
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
delay: 0
|
delay: 0
|
||||||
}).data('autocomplete')._renderItem = function (ul, item) {
|
}).data('autocomplete');
|
||||||
// item of completion list
|
|
||||||
var $item = $( "<li></li>" )
|
|
||||||
.data( "item.autocomplete", item )
|
|
||||||
.appendTo( ul );
|
|
||||||
|
|
||||||
if (item.facet !== undefined) {
|
// MonkeyPatch autocomplete instance
|
||||||
// regular completion item
|
_.extend(autocomplete, {
|
||||||
return $item.append(
|
_renderItem: function (ul, item) {
|
||||||
(item.label)
|
// item of completion list
|
||||||
? $('<a>').html(item.label)
|
var $item = $( "<li></li>" )
|
||||||
: $('<a>').text(item.value));
|
.data( "item.autocomplete", item )
|
||||||
}
|
.appendTo( ul );
|
||||||
return $item.text(item.label)
|
|
||||||
.css({
|
if (item.facet !== undefined) {
|
||||||
borderTop: '1px solid #cccccc',
|
// regular completion item
|
||||||
margin: 0,
|
return $item.append(
|
||||||
padding: 0,
|
(item.label)
|
||||||
zoom: 1,
|
? $('<a>').html(item.label)
|
||||||
'float': 'left',
|
: $('<a>').text(item.value));
|
||||||
clear: 'left',
|
}
|
||||||
width: '100%'
|
return $item.text(item.label)
|
||||||
});
|
.css({
|
||||||
};
|
borderTop: '1px solid #cccccc',
|
||||||
},
|
margin: 0,
|
||||||
/**
|
padding: 0,
|
||||||
* Gets value out of the currently focused "input" (a
|
zoom: 1,
|
||||||
* div[contenteditable].oe_searchview_input)
|
'float': 'left',
|
||||||
*/
|
clear: 'left',
|
||||||
currentInputValue: function () {
|
width: '100%'
|
||||||
return this.$el.find('div.oe_searchview_input:focus').text();
|
});
|
||||||
|
},
|
||||||
|
_value: function() {
|
||||||
|
return self.$el.find('div.oe_searchview_input').text();
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Provide auto-completion result for req.term (an array to `resp`)
|
* Provide auto-completion result for req.term (an array to `resp`)
|
||||||
|
|
Loading…
Reference in New Issue