SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Thread: highlighting

  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    highlighting

    Hello guys,
    I feel a bit silly opening this thread but I can't figure out what is wrong.

    I have in application.rhtml this code


    Code HTML4Strict:
    <div id="notice">
     <%= flash[:notice]%>
     <%= error_messages_for 'match' %>
    </div>


    and I would like to highlight the flash message once a new match is added so I put on add_match.rjs
    Code Javascript:
    page[:notice].visual_effect :highlight

    but it doesn't highlight anything. Why ??? Anywhere this kind of visual effect looks so easy to implement but I can't correctly implement it.


    I have included javascript libraries


    THANKS
    Alla prossima ...

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you calling this rjs page?

  3. #3
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by macsig View Post
    so I put on add_match.rjs
    Code Javascript:
    page[:notice].visual_effect :highlight
    THANKS
    Alla prossima ...

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, but you should have an Ajax call somewhere, like this:

    Code:
    link_to_remote '...', :action => 'add_match'

  5. #5
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, sorry only know I understand that I didn't understand your last post.

    Actually i don't have any link_to_remote

    Since I update a partial as well in the rjs file
    Code:
    page.replace_html 'matchList', :partial => "match", :collection => @match_list

    I have this at the end of add_match action
    Code:
     respond_to do |wants|
              wants.html { redirect_to :action => "add_match" }
              wants.js { render }
            end
    and this works for the partial
    Alla prossima ...

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using standard actions you do this:

    Code ruby:
    class SomeController < ApplicationController
      def example
        ...
      end
    end

    and you link to it like this:

    Code:
    <&#37;= link_to 'Example', :action => 'example'} %>
    But! When using Ajax you have to use link_to_remote:

    Code:
    <%= link_to_remote 'Example', :url => {:action => 'example'} %>
    If you use link_to you will get the wants.html (the redirect), and if you use link_to_remote you get wants.js (the rjs).

  7. #7
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello Fenrir,
    and thank you for your explanation but I have 1 more question:

    I see the difference between link_to and link_to_remote but I would like to use the visual effect after that my form has been submitted but I guess this is not possible since AJAX own nature. Isn't it ???


    Have a nice day !
    Alla prossima ...

  8. #8
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are quite a few options with link_to_remote that can allow you to control when a follow up action is triggered. Have a look at the documentation:

    http://api.rubyonrails.com/classes/A...r.html#M000533

    For example, the :loading option allows you to have your page display a message while the application is busy building the dynamic content.

    For your application, I would have thought the :complete option would suit. You could use this to trigger an action to highlight your text after and only when the process has completed successfully.

  9. #9
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you're already using RJS, you could do it like this:

    Code ruby:
    page.replace_html 'matchList', :partial => "match", :collection => @match_list
    page.visual_effect :highlight, 'matchList'

  10. #10
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my Rjs

    Code:
    page.replace_html 'matchList', :partial => "match", :collection => @match_list
    page[:notice].visual_effect :highlight
    I want to highlight the notice div

    but it looks like no to work


    THANKS GUYS
    Alla prossima ...

  11. #11
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the div[id="notice"] exist on that page? Does the first line of the RJS work?

  12. #12
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Does the div[id="notice"] exist on that page? Does the first line of the RJS work?
    Both answers are YES

    in my application.rhtml I have
    Code:
    	<div id="notice">
    		<%= flash[:notice]%>
    		<%= error_messages_for 'match'%>
    	</div>
    and once I add a new match the partial is rendered with the new list


    THANK YOU
    Alla prossima ...

  13. #13
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always use `page.visual_effect :highlight, :notice`. I don't know if your version works too, it could make a difference.

  14. #14
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically they work the same

    Anyway I tried your code and the result is the same as well: no highlight

    I really don't understand why the partial is updated but the highlight doesn't work

    Alla prossima ...

  15. #15
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post the Javascript that's generated from the RJS?

  16. #16
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my include (just to check out that everything is fine)

    script src="/javascripts/prototype.js?1192139124" type="text/javascript"></script>
    <script src="/javascripts/effects.js?1192139124" type="text/javascript"></script>
    <script src="/javascripts/dragdrop.js?1192139124" type="text/javascript"></script>
    <script src="/javascripts/controls.js?1192139124" type="text/javascript"></script>
    <script src="/javascripts/application.js?1192139124" type="text/javascript"></script>

    And this is the script

    <script type="text/javascript">
    //<![CDATA[
    new Form.Element.EventObserver('warehouse_main', function(element, value) {new Ajax.Updater('notice', '/warehouse/confirmed_new_main', {asynchronous:true, evalScripts:true, parameters:value})})
    //]]>
    </script>

    and this is the rjs (even I have given you already)

    page.replace_html 'warehouseList', artial => "warehouse", :collection => @warehouse_list
    page.visual_effect :highlight, :notice




    THANK YOU SO MUCH FOR YOUR HELP
    Alla prossima ...

  17. #17
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not *that* Javascript code, but the code generated from the RJS You can find it by pointing your browser at the url of the action that generates the RJS.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •