MooTools, form send function and b.lastIndexOf is not a function error

I am new to MooTools and was using MooTools 1.2.3 to submit a form via Ajax - pretty standard stuff. When trying to put in callbacks for onSuccess,onRequest, etc… I kept getting JavaScript errors (b.lastIndexOf is not a function). Looks like you need to use set() function first, then call send(). MooTools must have been updated, because there are a lot of examples on the intraweb that do not do this, but work in my browser. To add to my confustion, you can call send() on the form without set first as long as you don’t pass an object with callbacks as a parameter in send().
This works

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.send();
                })
            });

This does not work

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.send({onComplete:function(){alert('this');}});
                })
            });

This works with callbacks

            window.addEvent('domready', function() {
                $('myForm').addEvent('submit',function(event) {
                    event.preventDefault();
                    this.set('send',{onComplete:function(){
                            alert('this');
                        }
                    }).send();
                })
            });

Anyways, after a day of playing with MooTools, I have say I am impressed. Not sure why, but I think this is my favorite framework. I can’t say I have much experience with JS frameworks, and my JavaScript is pretty bad these days, but I am impressed with MooTools so far.

Leave a Reply