prototype.js problem&fix

8 views
Skip to first unread message

achernin

unread,
Sep 12, 2008, 11:44:43 AM9/12/08
to Prototype & script.aculo.us
prototype.js, Version: '1.6.0.2', Line 3462

focusFirstElement: function(form) {
form = $(form);
form.findFirstElement().activate();
return form;
},

this code is unsafe. findFirstElement() function returns empty value,
if form has no elements. look at this:

var elements = $(form).getElements().findAll(function(element) {
return 'hidden' != element.type && !element.disabled;
});

so, our solution is to rewrite focusFirstElement like this:

focusFirstElement: function(form) {
form = $(form);
var element = Form.findFirstElement(form);
if(!Object.isUndefined(element))
element.activate();
return form;
},

What do you think?

Regards,
Alexander Chernin, Naumen comp.

kangax

unread,
Sep 12, 2008, 12:48:36 PM9/12/08
to Prototype & script.aculo.us
Good catch.
I think there's no need for `isUndefined`:

focusFirstElement: function(form) {
form = $(form);
var element = form.findFirstElement();
element && element.activate();
return form;
}

Could you please file a bug report.
Thank you.

>
> Regards,
> Alexander Chernin, Naumen comp.

--
kangax

achernin

unread,
Sep 15, 2008, 2:58:14 AM9/15/08
to Prototype & script.aculo.us
done.
ticket #341
> --
> kangax
Reply all
Reply to author
Forward
0 new messages