javascript - Using getNext() with Mootools -


i'm trying autocompleter in mootools 1.11. works fine cant check if

this.selectel.getnext() 

is null or whatever. firebug outputs [li] every element , [null] non existing element output via getnext();

i saw people doing:

if(this.selectel.getnext()) {... 

but thats not working here because null object. terribly stupid must going on here...

here comes code around problem:

this.selectel = $$('ul.results').getfirst();  ...  oncommand: function(e, mouse) {     if (e.key && !e.shift) {          switch (e.key) {             case 'up':                                   this.selectel.getprevious().addclass('active');                 if(this.selectel) this.selectel.removeclass('active');                 this.selectel = this.selectel.getprevious();                 e.stop();              return;              case 'down':                 var test = this.selectel.getnext();                 console.log(typeof(test));                  if(this.selectel.getnext() != null) {  // not working                      this.selectel.getnext().addclass('active');                     if(this.selectel) this.selectel.removeclass('active');                     this.selectel = this.selectel.getnext();                 }                 e.stop();              return;          }     } 

your calling getnext() twice.

replace these lines:

if(this.selectel.getnext() != null) {  // not working    this.selectel.getnext().addclass('active');    if(this.selectel) this.selectel.removeclass('active');    this.selectel = this.selectel.getnext(); } 

with:

if(el = this.selectel.getnext() != null) {  // not working    el.addclass('active');    if(this.selectel) this.selectel.removeclass('active');    this.selectel = el; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -