Meanwhile, back on topic....
Something like $$('#my_area form') will not work because I sometimes don't
use form tags (for various reasons that I won't go into). At the most basic
level, I've got a bunch of input elements inside a container and I want to
enable/disable all of them, whether or not they are in a form is neither
here nor there.
The change in r5449 to work only with real form elements was probably more
significant than was realised at the time. I used to be able to use
Form.enable/disable more effectively, Form.serialize could also serialize
the form elements in any container (useful in places forms are not allowed,
like around table rows).
I can do the following to get the old behaviour back, but it's not very
nice.
var Container = Object.keys(Form.Methods).inject({}, function(container,
method) {
container[method] = function() {
var args = $A(arguments), element = $(args.shift());
var cache = Element.extend.cache, methods = Object.clone(Form.Methods);
for (var property in methods) {
var value = methods[property];
if (typeof value == 'function' && !(property in element))
element[property] = cache.findOrStore(value);
}
return Form[method].apply(null, [element].concat(args));
};
return container;
});
Now Container can be used instead of Form if you're not dealing with form
elements. Any other suggestions?
-Jonathan.
On 12/11/06, Christophe Porteneuve < [EMAIL PROTECTED]> wrote:
>
>
> Hey Jonathan,
>
> [EMAIL PROTECTED] a écrit :
> > Form.disable('my_area')
> >
> > This would disable all form elements in my_area, even though my_area
> > was not a form. As of r5449, Form.disable (as well as some other Form
> > methods) call methods like:
>
> Well, it's handy, but counter-intuitive and misleading, IMHO. You can
> do the same thing today like this:
>
> $($('my_area').getElementsByTagName('form')).invoke('disable');
>
> Sure, it's more verbose, but not humongously so, and at least it's a
> no-surprise code. If you're working on a small DOM, you can risk lower
> performance in order to achieve smaller code:
>
> $$('#my_area form').invoke('disable');
>
> > This will only work if the element is actually a form. Would anyone be
> > averse to going back to the old behaviour? It would simply mean
> > reverting back to things like Form.getElements instead of
> > $(form).getElements.
>
> Well, not so much reverting back as providing both behaviors, since it
> would be unacceptable to get rid of the latter form (this would be
> inconsistent with the whole remainder of the API, which provides the
> extension mechanism so code looks more OOP-like).
>
> > You could argue that you should only be using the Form methods on real
> > forms, but in practice it was useful not to have that restriction.
>
> It doesn't remove the feature; it just makes it slightly less
> "surprising," which I see as fitting the POLS...
>
> Now, that's just me. But reverting change on this specific case would
> introduce inconsistency with no great benefit, I believe.
>
> Just my two cents,
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark Twain
> Email: [EMAIL PROTECTED]
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---