Ajax.Updater - update vs replace

33 views
Skip to first unread message

Andrew Kaspick

unread,
Jan 25, 2008, 8:57:59 PM1/25/08
to prototy...@googlegroups.com
Hi,

Not sure if this has come up before, but I was thinking that an option
for Ajax.Updater to allow for a 'replace' call instead of the current
'update' would be useful.

I find that I don't always want to update a given section of html, but
would rather replace it entirely.

Thoughts?

As an aside for rails usage, remote methods could get an additional
:replace option to go along with the :update one if this functionality
was included in prototype.

Andrew

kangax

unread,
Jan 26, 2008, 2:36:13 AM1/26/08
to Prototype: Core
Simple subclassing should do the job (haven't tested but it should
work):

Ajax.Replacer = Class.create(Ajax.Updater, {
initialize: function($super, container, url, options) {
options = options || { };
options.onComplete = (options.onComplete ||
Prototype.emptyFunction)
.wrap(function(proceed, transport, json) {
$(container).replace(transport.responseText);
proceed(transport, json);
})
$super(container, url, options);
}
})

new Ajax.Replacer("someElement", "someUrl");

Andrew Kaspick

unread,
Jan 27, 2008, 4:33:46 AM1/27/08
to prototy...@googlegroups.com
So is this something worthy of core prototype?
Reply all
Reply to author
Forward
0 new messages