select-one-or-new formet

21 views
Skip to first unread message

Bob Sleys

unread,
Aug 10, 2011, 10:49:45 AM8/10/11
to hobo...@googlegroups.com
Ok I'm getting down the end, well end of the first release, of this project I'm working on.

One of the last major sticking points I have is monkeying with the formlet of a select-one-or-new tag.

What I need to do it hide one if the fields and set it's value to a preassigned value.  The field I'm hiding and presetting is a belongs_to relationship, thus I'm getting a select-one in the formlet for the field.

I've tried the following with no luck.

<extend tag="form" for="LocationMaterial">
  <old-form merge>
    <field-list: fields="material, condition, potential, friable, percent_damage, accessible, quantity, unit, notes">
      <material-view:>
        <select-one-or-new-dialog/>
      </material-view:>
      <unit-view:>
        <select-one-or-new-dialog/>
      </unit-view:>
    </field-list:>
  </old-form>
</extend>

<def tag="input" for="Material">
  <select-one include-none="&false"  options="&@building_materials"/>
   <formlet merge>
    <field-list: fields="name"/>
    <after-field-list:>test this</after-field-list:>
  </formlet>
</def>

Note the select-one options works fine so I'm getting into the materials input tag but the formlet merge isn't working.  In fact when I add it the new button drops down a line in the main form.  So it's doing something.

Here is the HTML without the <formlet>

<td class="material-view">
  <div class="part-wrapper" id="select-one--material">
    <select class="input belongs_to location_material_material" name="location_material[material_id]">
    <option value="2">Tile</option>
<option value="1">Wood</option>
  </select>
</div>
  <button class="hjq-dialog-open-button" onclick="hjq.dialog_opener.click(this, jQuery('#hjq-dialog--material')); return false;">
    New 
  </button>
 <span class="hjq-dialog-position"></span>
  <!-- json_annotation ({"buttons":[["cancel","hjq.dialog.close"],["ok","hjq.dialog.submit_formlet_and_close"]],"tag":"hjq-dialog","events":{},"init":"hjq.dialog.init","options":{"title":"New Material","autoOpen":false}}); -->
      </td>

and the HTML with it notice the added part in bold

<td class="material-view">
  <div class="part-wrapper" id="select-one--material">
    <select class="input belongs_to location_material_material" name="location_material[material_id]">
    <option value="2">Tile</option>
<option value="1">Wood</option>
  </select>
  <!-- json_annotation ({"ajax_options":{"url":null},"ajax_attrs":{},"tag":"formlet"}); -->
  <div class="material location-material-material formlet" name="location_material[material]"></div>
</div>
  <button class="hjq-dialog-open-button" onclick="hjq.dialog_opener.click(this, jQuery('#hjq-dialog--material')); return false;">
    New 
  </button>
 <span class="hjq-dialog-position"></span>
  <!-- json_annotation ({"buttons":[["cancel","hjq.dialog.close"],["ok","hjq.dialog.submit_formlet_and_close"]],"tag":"hjq-dialog","events":{},"init":"hjq.dialog.init","options":{"title":"New Material","autoOpen":false}}); -->
      </td>

Bob Sleys

unread,
Aug 10, 2011, 11:51:18 AM8/10/11
to hobo...@googlegroups.com
Just noticed I'm getting another error when trying to add a new item via select-one-or-new to a new record.  I added to the create of the controller per below:

class UnitsController < ApplicationController
...
  def create
    hobo_create do
      if request.xhr?
        self.this = LocationMaterial.new
      end
    end
  end
...
end

The new record is being created but I'm getting the following error in the console:

  Processing by UnitsController#create as JS
  Parameters: {"page_path"=>"/locations/5-floor", "render"=>{"0"=>{"part_context"=>"BAhbCTokc2VsZWN0X29uZV9vcl9uZXdfZGlhbG9nX3NlbGVjdCIKOnVuaXRb\nAFsHIhZsb2NhdGlvbl9tYXRlcmlhbCIJdW5pdA==--e8fe1ef51c4729e7a133460501f6d020afd806d3\n", "id"=>"select-one--unit"}}, "authenticity_token"=>"bWsM7rTxrD19qAL8j58xNyGO9JFiLp7yVKGeMeb6/no=", "unit"=>{"name"=>"alsdkllll"}}
  SQL (0.2ms)  SELECT COUNT(*) FROM "users"
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  AREL (0.2ms)  INSERT INTO "units" ("name", "created_at", "updated_at") VALUES ('alsdkllll', '2011-08-10 15:29:16.873016', '2011-08-10 15:29:16.873016')
Call part: select_one_or_new_dialog_select. this-id = :unit, locals = []
         : form_field_path = ["location_material", "unit"]
Completed   in 701ms

ArgumentError (invalid typed-id: :unit):
  app/controllers/units_controller.rb:8:in `create'


Note units_controller.rb:8 is the hobo_create do line.

Bob

Bob Sleys

unread,
Aug 11, 2011, 11:25:10 AM8/11/11
to hobo...@googlegroups.com
I getting the above error on any select-one-or-new tag when creating a new item.  

IE for the model assocationt Parent->Child

On the Parent new form if I select the new button (from the select-one-or-new tag) to create a new Child I get the error

ArgumentError (invalid typed-id: :child):

The child gets saved to the database but then the above error is thrown and the formlet isn't closed nor is the select list updated to show the new child.

This is with adding to the controller

 def create
    hobo_create do
      if request.xhr?
        self.this = Parent.new
      end
    end
  end

Bob
Reply all
Reply to author
Forward
0 new messages