<select-one-or-new>

Adds a small button to a select in order to create a new record within a modal

For example, if I want to create a new project in stories/new.dryml:

<new-page>
  <form:>
    <field-list:>
      <project-view:><select-one-or-new/></project-view:>
    </field-list:>
  </form:>
</new-page>

You also need to modify the create action of the new record. projects_controller.rb:

def create
  hobo_create do
    @this = Story.new(:project => @project)  if request.xhr?
    create_response
  end
end

If you are instead in stories/edit.dryml, you need to make sure the new project is autoselected. Add a couple of lines to the previous code:

def create
  hobo_create do
    if request.xhr?
      @this = Story.new(:project => @project)
      ajax_update_response(params[:render].values, {}, {:postamble => 
        "$('#select-one-or-new-Project').val(#{@project.id});"})
    else
      create_response
    end
  end
end

Show Source


Edit this page