On 06 Jul 2010, at 14:47, Lille wrote:
I'd like to make the :confirm option in my link_to/button_to erb
elements conditional. So, if the page is in some state, no
confirmation is requested, but not otherwise, etc.
So far, my only (ugly) approach is to replace the linker html itself
depending on changes in state, but I believe there must be an easier
way to 'toggle' the confirmation option on/off.
Can anyone recommend an approach?
Write your own Javascript which handles these page state changes and
confirmation instead of relying on Rails Javascript helpers. Those
helpers were only made for the most basic operations. You wouldn't use
a teaspoon to empty a bath either, even if you could put a bigger
handle on the spoon.
Flow:
- Observe link clicks (you can add a class="confirmable" or something
to them if you want to apply it only to that element)
- Observe the elements on the page that will trigger a state change
- If those elements are changed, add the state to window or something
- When a link is clicked, it should see if window.state_changed ==
true and display the confirmation, if not, just window.location ==
link.href
You would be best off implementing this in an event delegated way if
there's a lot of elements that can change the page state, as well as
new elements being injected into the page via AJAX.
Best regards
Peter De Berdt
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" 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-talk?hl=en.