#15 awaiting-merge
kwerle

click_button an image button should send X/Y coordinates as params

Reported by kwerle | September 5th, 2008 @ 12:32 PM

I have an image button in a form. There doesn't seem to be any easy? way to click it.

Comments and changes to this ticket

  • kwerle

    kwerle September 5th, 2008 @ 12:40 PM

    Ah. This looks like a dupe of #8.

  • kwerle

    kwerle September 5th, 2008 @ 04:10 PM

    This is somewhat resolved in the git repository. webrat is in dire need of a new release.

    clicks_button on an image button fails to send some expected button data.

    ...

    Clicking that should send all the form data and "button_name.x"=>"0", "button_name.y"=>"0", "action"=>"some_action"

  • kwerle

    kwerle September 5th, 2008 @ 04:26 PM

    This is somewhat resolved in the git repository. webrat is in dire need of a new release.

    clicks_button on an image button fails to send some expected button data.

    ...
    
    <input alt="Alt Tag" name="button_name" src="source.gif"  title="Title" type="image" />
    </form>
    
    Clicking that should send all the form data and
    "button_name.x"=>"0", "button_name.y"=>"0", "action"=>"some_action"
    
  • kwerle

    kwerle September 5th, 2008 @ 05:02 PM

    ButtonField diff:

    
         def to_param
    -      return nil if @value.nil?
    -      super
    +      if @value.nil?
    +        return_hash = {}
    +      else
    +        return_hash = super
    +      end
    +      if ! @element["src"].blank?
    +        return_hash["#{name}.x"] = 0
    +        return_hash["#{name}.y"] = 0
    +        #value = @value.to_s.gsub('&', '%26')
    +        #param_parser.parse_query_parameters("#{name}=#{value}")
    +      end
    +      return_hash
         end
    
  • kwerle

    kwerle September 5th, 2008 @ 06:02 PM

    Doh! That will do the .x.y for all image buttons in the form. It should only post for the clicked one:

    
         def to_param
    -      return nil if @value.nil?
    -      super
    +      if @value.nil?
    +        return_hash = {}
    +      else
    +        return_hash = super
    +      end
    +      if @clicked && ! @element["src"].blank?
    +        return_hash["#{name}.x"] = 0
    +        return_hash["#{name}.y"] = 0
    +        #value = @value.to_s.gsub('&', '%26')
    +        #param_parser.parse_query_parameters("#{name}=#{value}")
    +      end
    +      return_hash
         end
    
         def default_value
    @@ -145,6 +155,7 @@
    
         def click
           set(@element["value"]) unless @element["name"].blank?
    +      @clicked = true
           @form.submit
         end
    
  • Bryan Helmkamp

    Bryan Helmkamp October 25th, 2008 @ 05:02 PM

    • Title changed from “Can't seem to clicks_button an image button” to “click_button an image button should send X/Y coordinates as params”
  • gaffo

    gaffo January 6th, 2009 @ 07:57 PM

    • Tag set to featurerequest, patch

    Brynary, what's the state on this one.

  • Mike Burns

    Mike Burns January 6th, 2009 @ 08:56 PM

    I've made a patch against the master branch for adding optional arguments to #click_button. This way you can do:

    click_button 'button-id', :x => 5, :y => 100

  • Bryan Helmkamp

    Bryan Helmkamp January 7th, 2009 @ 12:43 PM

    Is it sufficient to pass in an X/Y of 0,0 or 1,1, or is anyone doing anything that depends on the exact values?

    I don't really want to add :x and :y as options that click_button takes if at all possible.

  • kwerle

    kwerle January 7th, 2009 @ 01:00 PM

    Remember image maps!? Pretty sure they want an exact coordinate - but I've never actually used 'em.

    Certainly the data is possible to extract from the form submit. I'm sure someone, somewhere wants to know exactly where the user clicked...

  • gaffo

    gaffo May 7th, 2009 @ 01:04 PM

    • State changed from “new” to “awaiting-merge”
  • JM

    JM August 3rd, 2009 @ 10:40 AM

    As I did not manage to apply the patch attached by Mike Burns on the latest master, I slightly changed his code and the tests in order to add this feature I really need for my current project.

    You can find the commit here: http://github.com/garnierjm/webrat/commit/ac27bebab2c90e396609b43d0...

    It should be quite easy to merge now :-)

    The optional param to click_button is probably not the most beautiful API change but it does the work. Ideally, webrat would automatically add a random x and y coordinate for the image button to the params. Like in the real world ...

    Could it be possible to add this feature now and change it later?

  • JM

    JM August 3rd, 2009 @ 11:15 AM

    I just added a gemspec on my fork of webrat in order to generate a gem on github. You can install it with:

    sudo gem install garnierjm-webrat
    
  • Andreas Henning

    Andreas Henning June 26th, 2012 @ 06:44 AM

    • Milestone order changed from “0” to “0”

    Hi

    Has anything happened to this ticket in the last 3 Years? :)
    I cloned the repository and built version 0.7.5, but the ImageButton behaviour is still kind of ... missing :)

    Thanks in advance,
    TJ

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Attachments

Referenced by

Pages