== 22 August Patch from Daniel P. Zepeda * Not to pollute production code. Load only in 'testing' environment == 11 August Accepted patch from Jason Garber * Allow use of hpricot_forms methods in Integration tests * Include textareas in field_names and allow read/write of textarea text * Handle multiple input tags with the same name just like a browser would * Submit the proper value with Rails' checkbox-hidden input combination * Form submits to itself when no action specified (just like a browser) == 20 July form.extend!(partial) Since some of us like to use Javascript to extend a form, HpricotForms should allow for setting of non-existing fields in a controlled manner. Now you can now use extend() to do that, e.g: form = page.forms.first form["email[0]"] = "email1" form.extend do # any field name you want form["email[1]"] = "email1" form["email[2]"] = "email1" end form["from"] = "sender" page = form.submit(self) Or, actually the preferred mechanism is to add with a rendered partial. e.g. if you have an 'Security Options' link that when clicked, fetches a partial page from the server and extends the existing form with more fields, you can do this: form = page.forms.first form.field_names # => ["email[0]"] # the original form only has 1 field form["email[0]"] = "email1" # extend and assign in block... form.extend!(get(:on_security_options_clicked)) do form.field_names # => ["email[0]", "ssl"] # the new fields from the partial is # appended into our form object. form["ssl"] = "true" end # or extend first, assign later form.extend!(get(:on_privacy_options_clicked)) form.field_names # => ["email[0]", "ssl", "sharing"] # the new fields from the partial is # again appended into our form object. form["sharing"] = "false" form["from"] = "sender" page = form.submit(self) # the doubly-extended form is submitted whole The advantages of extending with partial is 1) existence of field names are enforced. 2) default values that comes with the partials are automatically included as well But becareful - if the partial is rendered by RJS, be sure to use respond_to() and include the option to render back pure HTML, e.g. # from this: def on_privacy_options_clicked render :update do |page| page.replace params[:dom_id], render(:partial => '/forms/privacy') end end # change to this: def on_privacy_options_clicked render_opts = {:partial => '/forms/privacy'} respond_to do |format| format.html { render(render_opts) } format.js { render :update do |page| page.replace params[:dom_id], render(render_opts) end } end end checkboxes Multivalued fields should be dealt with (more) correctly now, e.g: form["hobbies[]"] = ["cycling", "swimming"] form["hobbies[]"] # => ["cycling", "swimming"] form.to_code() Convenience method to easily construct test code, e.g: form = page.forms.first puts form.to_code # this prints lines of Ruby code like: # # form["from"] = "sender" # form["email[0]"] = "email1" # form["options[]"] = ["html", "read-receipt"] # # Convenient to copy-and-paste to start writing your test code with.