Can one restore the "Save Model / Cancel" buttons if one replaced the contents of a "new" form?

29 views
Skip to first unread message

Peter Pavlovich

unread,
Feb 1, 2012, 3:08:52 PM2/1/12
to Hobo Users
I have a situation in which I would like to create a custom input form
for a given model but I would like to keep the standard form buttons
at the bottom of the form ("Save XXX" and "Cancel"). Is there a way in
DRYML to do this? In other words, are the buttons contained in a
restorable tag parameter?

Thanks in advance!

Peter

Peter Pavlovich

unread,
Feb 1, 2012, 3:55:27 PM2/1/12
to Hobo Users
Also, what about the form header and title including the actual <form> tag?

Thanks!

Peter


Peter

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.


Ignacio Huerta

unread,
Feb 1, 2012, 4:08:15 PM2/1/12
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Peter,

Have you tried replacing the field-list inside the form? I think this
would be the easiest way. You can also take a look at the default
automatic dryml generated in app/views/taglibs/auto, maybe it helps :)

<new-page>
<form:>
<field-list: replace>
<!-- Your custom inputs -->
</field-list:>
</form:>
</new-page>

Regards,
Ignacio

El 01/02/12 21:55, Peter Pavlovich escribi�:


> Also, what about the form header and title including the actual
> <form> tag?
>
> Thanks!
>
> Peter
>
> On Wed, Feb 1, 2012 at 3:08 PM, Peter Pavlovich
> <pavl...@gmail.com <mailto:pavl...@gmail.com>> wrote:
>
> I have a situation in which I would like to create a custom input
> form for a given model but I would like to keep the standard form
> buttons at the bottom of the form ("Save XXX" and "Cancel"). Is
> there a way in DRYML to do this? In other words, are the buttons
> contained in a restorable tag parameter?
>
> Thanks in advance!
>
> Peter
>
> -- You received this message because you are subscribed to the
> Google Groups "Hobo Users" group. To post to this group, send email

> to hobo...@googlegroups.com <mailto:hobo...@googlegroups.com>.

> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com

> <mailto:hobousers%2Bunsu...@googlegroups.com>. For more


> options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.
>
>
> -- You received this message because you are subscribed to the
> Google Groups "Hobo Users" group. To post to this group, send email
> to hobo...@googlegroups.com. To unsubscribe from this group, send
> email to hobousers+...@googlegroups.com. For more options,
> visit this group at
> http://groups.google.com/group/hobousers?hl=en.

- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8pqb0ACgkQBPlUJ6RHaOQ8dgCfTvxI2Vllynmf8Q4iOayafrpc
YQYAmwQCGbKeoIqHBMVEFatObyQYU1s6
=2K0o
-----END PGP SIGNATURE-----

Bryan Larsen

unread,
Feb 2, 2012, 9:40:03 AM2/2/12
to hobo...@googlegroups.com
I suspect that Ignacio suggested what you really want, but to directly
answer your question, you can do something like to switch the order

<form>
<field-list: replace></field-list:>
<actions: replace>
<div>Hello</div>
<actions restore/>
<field-list fields="foo,bar"/>
</actions>
</form>

Notice that I'm restoring actions but I'm removing field-list and
replacing with a new one.

Bryan

Peter Pavlovich

unread,
Feb 2, 2012, 10:51:45 AM2/2/12
to hobo...@googlegroups.com
Thanks for the advice and help. I am still new to the DRYML / Hobo world so I apologize in advance for any newbie-level questions. I tried the suggestion above but got an error. I suspect I am missing something fairly basic, like passing the @variable around properly but I've tried putting "merge" in a bunch of places with no joy. So, in the hope that someone will be able to spot my problem, here is my "new" method in the controller:

  def new
  @z = Registration.new
  @x = Person.new
  @y = Person.new
    hobo_new
  end


And here is what I used for the "new.dryml" page definition:

<new-page>
    <form:>
        <field-list: replace>
            <person-editor with="&@x" type="some-attrib-value-1">
            <legend:>a param value for the person-editor tag</legend:>
            </person-editor>

            <person-editor with="&@y" type="some-attrib-value-2">
               <legend:>a different param value for the person-editor tag</legend:>
            </person-editor>

            <registration-editor with="&@z" />
        </field-list:>
    </form:>
</new-page>

Here is the "person-editor" tag def from application.dryml:

<def tag="person-editor" attrs="type">
 <div class="#{type}_info" id="#{type}_info" >
 <fieldset>
   <legend param>Person Details</legend>
   <table>
  <labeled-field name="first_name" />
  <labeled-field name="last_name" />
  <labeled-field name="home_phone" />
  <labeled-field name="cell_phone" />
  <labeled-field name="email" />
    <labeled-field name="contact_name" />
  <labeled-field name="contact_phone" />
  </table>
 </fieldset>
 </div>
</def>

And here is the error I am receiving:

DRYML cannot provide the correct form-field name here (this_field = "first_name", this = nil)
With a stack trace of:

app/views/taglibs/application.dryml:12:in `block in labeled_field'
app/views/taglibs/application.dryml:6:in `labeled_field'
app/views/taglibs/application.dryml:22:in `block (3 levels) in person_editor'
app/views/taglibs/application.dryml:21:in `block (2 levels) in person_editor'
app/views/taglibs/application.dryml:21:in `block in person_editor'
app/views/taglibs/application.dryml:17:in `person_editor'
app/views/registrations/new.dryml:4:in `block (4 levels) in render_page'
app/views/registrations/new.dryml:3:in `block (3 levels) in render_page'
app/views/taglibs/auto/rapid/forms.dryml:64:in `block (3 levels) in form__for_registration'
app/views/taglibs/auto/rapid/forms.dryml:62:in `block (2 levels) in form__for_registration'
app/views/taglibs/auto/rapid/forms.dryml:62:in `block in form__for_registration'
app/views/taglibs/auto/rapid/forms.dryml:61:in `form__for_registration'
app/views/taglibs/auto/rapid/pages.dryml:688:in `block (6 levels) in new_page__for_registration'
app/views/taglibs/auto/rapid/pages.dryml:687:in `block (5 levels) in new_page__for_registration'
app/views/taglibs/auto/rapid/pages.dryml:687:in `block (4 levels) in new_page__for_registration'
app/views/taglibs/auto/rapid/pages.dryml:678:in `block (3 levels) in new_page__for_registration'
app/views/taglibs/themes/clean/clean.dryml:2:in `block in page_with_aaa82d3a9ca5'
app/views/taglibs/themes/clean/clean.dryml:1:in `page_with_aaa82d3a9ca5'
app/views/taglibs/front_site.dryml:12:in `block in page_with_a46705120a36'
app/views/taglibs/front_site.dryml:11:in `page_with_a46705120a36'
app/views/taglibs/auto/rapid/pages.dryml:675:in `block in new_page__for_registration'
app/views/taglibs/auto/rapid/pages.dryml:674:in `new_page__for_registration'
app/views/registrations/new.dryml:1:in `block in render_page'
app/views/registrations/new.dryml:1:in `render_page'
app/views/registrations/new.dryml:1:in `_app_views_registrations_new_dryml___3696370354641707024_70364650484020_3277638183384190033'
Any assistance would be most greatly appreciated!

Regards,

Peter

kevinpfromnm

unread,
Feb 2, 2012, 11:17:06 AM2/2/12
to hobo...@googlegroups.com
In order for the create action to handle multiple models they have to be related to a single original model and have the :accessible => true flag on the association.

For it to work as an ajax editor, you'd need individual editor calls on each field (plus I think the way you're using table might be throwing off the implicit context).  But, an in place editor won't work on an unsaved object or possibly worse, will have the possibility of setting up orphaned records (go to new form, main object unsaved, children unsaved, make edit to child, child now saved, leave new form, no main object).

I would guess you either want these as accessible associations or you'll need a two step process where you do the new object first, then have the sub-items setup on a second page, like the show view.  The accessible association is by far the more common pattern -> http://cookbook.hobocentral.net/manual/multi_model_forms.

Peter Pavlovich

unread,
Feb 2, 2012, 1:25:31 PM2/2/12
to hobo...@googlegroups.com
Hmmmm ... Ok. So let's say I have a person object (instance of Person) which has a home address (instance of Address) and a business address object (instance of Address). I set up the Person like this:

class Address < ActiveRecord::Base
  hobo_model
  fields{
    ... bunch of fields ...
  }
  has_many :people
end

class People < ActiveRecord::Base
  hobo_model
  fields {
    ... bunch of fields ...
  }
  belongs_to :home, :class_name => "Address", :foreign_key => "home_id"
  belongs_to :work, :class_name => "Address", :foreign_key => "work_id"
end

So, given that you want to create a combined "new" screen which would allow me to use two copies of a tag like "address-editor" to add both a home and a business address in-line with the rest of the info about a person on the "new" person screen, how would one accomplish that? I had thought to do something like the following in the "new" method of the controller:

  def new
  @person = Person.new
  @work = Address.new
  @home = Address.new
    hobo_new
  end
 
and then do sort of as I had suggested in my example above and have these things edited directly and then, in the "save" method of the controller, build the model structure from what the form passes back to me before calling "save" on it. 

Any other suggestions? Surely, someone else must have had to have an "inline" editor for a "child" model like this, no?

Again, any help for a newbie here would be greatly appreciated!

Regards,

Peter

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/-GFpDitcgzEJ.

kevinpfromnm

unread,
Feb 2, 2012, 2:50:00 PM2/2/12
to hobo...@googlegroups.com
No, your new would be something like:

def new
  hobo_new # this sets up a new Person or grabs the info from the form
  @person.home.build if @person.home.blank? # make a new address for home association if there isn't one
  @person.work.build if @person.work.blank? # similarly
end

You'll also need to add :accessible => true on the home and work associations in the person model.

You might be able to get by with the default form after you set that option though I'm not 100% sure with belongs_to associations.

Peter Pavlovich

unread,
Feb 2, 2012, 4:52:07 PM2/2/12
to Hobo Users
Ok. Thank you for the help! Just one clarifying question, if I may:

Are you saying that "hobo_new" creates a new instance of the main
model and assigns it to @model-class-name (e.g. in your example,
@person), or did you mean that it creates it and assigns it to @this
which would mean your example should read:

def new
hobo_new # this sets up a new Person or grabs the info from the
form
@this.home.build if @this.home.blank? # make a new address for home
association if there isn't one
@this.work.build if @this.work.blank? # similarly
end

Just trying to understand hobo-isms.

Thanks again!

Peter

kevinpfromnm

unread,
Feb 2, 2012, 5:38:41 PM2/2/12
to hobo...@googlegroups.com
actually both though typically you don't use @this directly.
Reply all
Reply to author
Forward
0 new messages