hi group,

I am making a little rails app to experiment with rails. It consists
of one model, item, that represents an item on a todo list.
A todo item has a description, a state (finished or not) and a due
date.
 After changing the scaffold screens a bit, I wanted to be able to
have no due date. I tried to do this by making a radio button; if 'no
date' is selected, the date selection field should be disabled.

I have something working now, but I have this feeling that it is not
exactly how it should be done in rails. Appended to this mail is my
app/views/item/edit.html.erb. Comments/suggestions welcome!
Especially the javascript part is bothering me: should it really be
included in the html.erb file and at that point? Another thing is the
radio_button_tags with the onclick. This is not good, is it?

thanks in advance, Ruud


===========================
edit.html.erb (hopefully the tags are preserved in the mail)

<h1>Editing item</h1>
<script type='text/javascript'>
function date_clicked (noDate)
{
    var doc = window.content.document;
    doc.getElementById( 'dagid').disabled = noDate;
    doc.getElementById( 'mid').disabled = noDate;
    doc.getElementById( 'jid').disabled = noDate;
}
</script>

<% form_for(@item) do |f| %>
  <%= f.error_messages %>
<table>
    <tr>
        <td><%= f.label :description %></td>
        <td><%= f.text_area( :description, { :cols  => 40,
                                            :rows   => 2}) %></td>
    </tr>
    <tr>
        <td>finished</td>
        <td><%= check_box_tag( 'finished', @item.finished) %></td>
    </tr>
    <tr>
        <td><%= f.label :priority %></td>
        <td><%= f.select( :priority, [ 1, 2, 3, 4, 5,]) %></td>
    </tr>
    <tr>
        <td><%= radio_button_tag(  'datum', 'none', @nodate , {
                                        :name       => 'datum',
                                        :value      => 'none',
                                        :onclick    => 'date_clicked
(true)'
                                            }) %>
        <%= f.label( 'no date' ) %></td>
        <td></td>
    </tr>
    <tr>
        <td><%= radio_button_tag( 'datum', 'with', !...@nodate, {
                                        :name       => 'datum',
                                        :value      => 'with',
                                        :onclick    => 'date_clicked
(false)'
                                            }) %>
            <%= f.label( 'due date' ) %></td>
        <td>
    <%= select_day( @day, { :disabled => @nodate }, { :id => 'did',
                                :name => 'dname' }) %>
    <%= select_month( @month, { :disabled => @nodate }, { :id =>
'mid',
                                :name => 'mname' }) %>
    <%= select_year( @year, {   :disabled => @nodate ,
                                :start_year => 2009 },
                            {   :id => 'jid',
                                :name => 'jname' }) %></td>
      </tr>
  </table>
    <%= f.submit "change" %>
<% end %>
<%= link_to 'show', @item %> |
<%= link_to 'back', items_path %>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to