Development

#2342 ([PATCH] sfBrowser::click() should also search for <button> elements)

You must first sign up to be able to contribute.

Ticket #2342 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

[PATCH] sfBrowser::click() should also search for <button> elements

Reported by: Jeroen Assigned to: fabien
Priority: major Milestone: 1.0.9
Component: tests Version: 1.0.7
Keywords: Cc:
Qualification: Unreviewed

Description

In my HTML forms I most often use <button> elements as buttons, instead of <input type="submit|button">. This allows me easy access in my CSS files to style the form buttons.

But the method sfBrowser::click() fails to search for <button>-element, as it only searches for a possible <input> element. Therefore I'm proposing the attached patch to also search for <button> elements, of which either the name-attribute or the contents matches the $name-parameter to this method. (the patch was made against revision 4750)

Attachments

sfBrowser.class.patch (0.9 kB) - added by Jeroen on 10/05/07 17:42:49.

Change History

10/05/07 17:42:49 changed by Jeroen

  • attachment sfBrowser.class.patch added.

(follow-up: ↓ 5 ) 10/12/07 14:10:49 changed by dhooge

To have more control on my buttons I decided to switch to the BUTTON element. But now, all my tests are indeed broken. So I also think this would be good to have such a test in sfBrowser.

However, I don't agree with Jeroen's patch. The test must be done on the value attribute, not the name one. This is more compatible with what is done for INPUT elements.

@@ -333,7 +333,10 @@
     // form
     if (!$form = $xpath->query(sprintf('//input[((@type="submit" or @type="button") and @value="%s") or (@type="image" and @alt="%s")]/ancestor::form', $name, $name))->item(0))
     {
-      throw new sfException(sprintf('Cannot find the "%s" link or button.', $name));
+      if (!$form = $xpath->query(sprintf('//button[@value="%s"]/ancestor::form', $name))->item(0))
+      {
+        throw new sfException(sprintf('Cannot find the "%s" link or button.', $name));
+      }
     }

10/12/07 16:41:11 changed by dhooge

[Out of Topic] Note that using <button> instead of <input> is a good practice for I18N, because the value of the button is never displayed to the end-user.

10/12/07 17:12:42 changed by noel

  • milestone set to 1.0.9.

10/15/07 11:11:34 changed by dhooge

BTW, it would be even better if the value of the button is also automatically added to the form data. As a workaround, I use:

-> setField($btn_name, $btn_value)
-> click($btn_value)

(in reply to: ↑ 1 ) 10/21/07 09:25:04 changed by Jeroen

Replying to dhooge:

However, I don't agree with Jeroen's patch. The test must be done on the value attribute, not the name one. This is more compatible with what is done for INPUT elements.

dhooge is absolutely right here, so please ignore my patch and apply dhooge's patch

10/22/07 09:41:04 changed by dhooge

Added a ticket to have a button creation helper (#2425)

11/21/07 11:07:41 changed by noel

  • status changed from new to closed.
  • resolution set to fixed.

(In [6129] and [6130]) ->click() also search for button elements