autocomplete - JavaScript exception

UI Components for JSF
Post Reply
alnikolov
Posts: 2
Joined: 02 Dec 2011, 18:30

02 Dec 2011, 20:10

PrimeFaces version: 3.0M4/RC1 - built from source with disabled compression of the script files.
JSF: Mojarra 2.1.3
Container: Glassfish 3.1

After adding an autocomplete component to my page I started receiving odd JavaScript exceptions. After debugging the script with FireFox, I came upon the following code:

autocomplete.js

Code: Select all

181:  //hide overlay when outside is clicked
182:    var offset;
183:    $(document.body).bind('click', function (e) {
184:        if(_self.panel.is(":hidden")) {
185:            return;
186:        }
187:        offset = _self.panel.offset();
188:        if(e.target === _self.input.get(0)) {
189:            return;
190:        }
191:        if (e.pageX < offset.left ||
192:            e.pageX > offset.left + _self.panel.width() ||
193:            e.pageY < offset.top ||
194:            e.pageY > offset.top + _self.panel.height()) {
195:            _self.hide();
196:        }
197:        _self.hide();
198:    });
The exception was thrown on line 191 saying that offset is undefined.
The check on line 191 is redundant because the _self.hide(); will be executed regardless of the value of offset.
My fix for the problem was as below:

Code: Select all

181:  //hide overlay when outside is clicked
182:    $(document.body).bind('click', function (e) {
183:        if(_self.panel.is(":hidden")) {
184:            return;
185:        }
186:        if(e.target === _self.input.get(0)) {
187:            return;
188:        }
189:        _self.hide();
190:    });
Thanks for the great library.

Take care,
Aeksandar Nikolov

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests