Defines a <select-one> and a button that brings up an <dialog-box> containing a form allowing you to enter a new item. After the form is filled in and closed, the <select-one> is changed to select the new item.


  • or
  • dialog-open-button
  • dialog-box
    • field-list


select-one-or-new-dialog is a very simple control that depends on a large number of Hobo and hobo-jquery components to be working correctly in the standard manner. These include ajax, a standard form context, and formlets.

sort order

The javascript for this control is a quick hack that assumes the new item created will be the last item in the select. If you’ve defined a sort order, this assumption will be broken. It will also be broken if there are more items than the select-one limit.

parameterizing parts

Because the select-one is a part, it cannot be parameterized. However, you can adjust its definition by defining the polymorphic input for the type:

<def tag="input" for="StoryStatus">
  <select-one include-none="&false" />

controller actions

For Hobo ajax to work, standard controller actions are required. If you have customized the sub-item’s create action, you may break select-one-or-new-dialog.

There is one case where you have to customize the create action. For Ajax to work, Hobo has to resurrect the context. This is straightforward if the parent context exists in the database. If it does not, then Hobo uses whatever ‘this’ is created by the controller action. In our case, this is usually the wrong thing.


class Story
  fields do
    name :string
  belongs_to :story_status
  # plus permissions, etc...




class StoryStatusesController < ApplicationController
  def create
    hobo_create do
      if request.xhr?
        self.this = Story.new

Just to be clear, you shouldn’t need any special controller actions if you are using inside of edit forms. It’s only when you’re using it inside of a new form that Hobo cannot load the object from the database so you have to tell it the context.

FIXME: translate ‘or’, ‘New’, ‘cancel’, ‘ok’.

Show Source

Edit this page