Hi, I'm fighting with Ajax forms in a table.
The goal of the application is to have multiple named sets of data points,
one set per row, where new data points may be entered in the same row:
Dataset name | Sum X | Sum Y | Add X | Add Y |
--------------+-------+-------+---------+---------+--------
Measurement 1 | 100 | 200 | [Input] | [Input] | [Submit]
Measurement 2 | 120 | 220 | [Input] | [Input] | [Submit]
In the end, I would like to use a sortable table, but I'm starting small.
Datapoint has x and y fields (floats) and belongs_to :dataset.
Dataset has a title field (string) and sum_x, sum_y methods, which sum the
datapoints (avoiding the nil pitfalls created by <form:datapoints.new> :-)).
It works when I use the card format with minimal markup:
<def tag="card" for="Dataset">
<card class="dataset" param="default" merge>
<header: param>
<a><name/></a> | <do part="dataset"><view:sum_x/> | <view:sum_y/> |
<form:datapoints.new ajax
refocus-form><input:x/><input:y/><submit label="Add"/></form></do>
</header:>
<body: param/>
</card>
</def>
However, I have been unable to put this in a table. The plan was to have
the <tr> as the part, wrapping a <form> which in turn wraps the <td>s with
one <view> or <input> each. The problems are as follows:
- Setting a "part=" attribute on <tr> results in "undefined method
`all_parameters' for #<#<Class:0x007fdf214ab958>:0x007fdf214b3888>"
- Wrapping the naked <tr> in <do part="foo"> has the same problem
- Having the form span the <td>s results in an OK-looking page, but when
submitting the Ajax form, it results in "Couldn't create the Datapoint. X
can't be blank, Y can't be blank"
The closest thing to working is this (modelled after <table> tag):
- The entire <form> is in one <td>, defeating the <table> layout.
- The sums are not updated by Ajax, only by a manual refresh.
- Even when changing the sum_y view to <view part="sum-x"
id="sum-x-#{scope.dataset.typed_id}"/> and adding an explicit
'update="sum-x-#{scope.dataset.typed_id}"' or 'updates="#sum-x-…"' to the
<form>, no update happens.
What am I doing wrong?
-Marcel
<datapoints-table with="&Datapoints.all">
<title-view:><a with="&this_parent"><view:title/></a></title-view:>
</datapoints-table>
<def tag="datapoints-table">
<unless test="&(this.nil? || this.empty?) && !empty">
<table class="datapoints-table">
<thead>
<tr><th>Dataset name</th><th>Sum X</th><th>Sum Y</th><th>Add X</th><th>Add
Y</th></tr>
</thead>
<tbody>
<tr repeat>
<set-scoped dataset="&this">
<do with="&scope.dataset">
<with-fields fields="title, sum_x, sum_y">
<td param="#{scope.field_name.to_s.sub('?',
'').gsub('.', '-')}-view"><view/></td>
</with-fields>
</do>
<td param="datapoint-input">
<form:records.new ajax refocus-form>
<input:x/>
<input:y/>
<submit label="Add"/>
</form>
</td>
</set-scoped>
</tr>
</tbody>
</table>
</unless>
</def>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.