Actually, let's talk about the Where. I've been talking about positionally adding content to DIV's, throwing around symbols like: before_begin
, after_begin
, before_end
, and after_end
. But what do they mean? Where is the content going using these different update methods?
I'm glad you asked -- saved me the trouble. It will position the new content relative to the target element. Specifically, in Rails, the element with the id you give as the :update
param to form_remote_tag
. Example:
<%= form_remote_tag( :url => url_for( :action=>'ajax_method'), ) %>
In this case, the :update_method
is relative to an element with the id of 'my-target-div'. OK, so we know where the after_begin
method is relative to, where exactly will it put it? Another good question!
So, the target element is the big gray box in the middle. The blue and red boxes are where the content returned from AJAX.Updater
will be put, based on the update_method
. Notice the red boxes are not in the target element, but the blue boxes are. That's the reason why append
and prepend
aren't enough to exactly specify where the content is going. If we wanted to limit ourselves to those two update methods, we'd have to make some up some arbitrary rules stating that the content is always inside the target element. Which could be done, but I'd rather not have that as a limitation.
Although I've gone down the path of making the update_method
mimic the IE nomenclature for insertAdjacentHTML
, I think different names for the update methods would clear up some of the ambiguity. The right column of the above diagram has my recommended update method names.
In short, before_begin
would become before
, after_begin
would be top
, before_end
would be bottom
, and after_end
would be after
. If this makes sense, then I think I will rework and resubmit my patch to Rails.
Any thoughts or suggestions?
No comments:
Post a Comment