I'm trying to use Ruby on Rails' Formbuilder and HAML to edit a model that has some fields that can only be edited a creation. I still want to display them, but I don't want them editable. I've struggled trying to do this and make the form look presentable. So, if the field is editable, I use
= f.text_field :price_code_1, :label_name => 'Price Code 1: (Selling Price)'
But the UPC is not changeable, and this does NOT work:
= f.text_field :upc, :label_name => 'UPC', :disabled => 'disabled'
I end up doing this, but it is butt-ugly:
<p><label class="field_label" for="upc">UPC</label><input class="medium_text_field" id="_sku_upc" name="[sku][upc]" type="text" value="#{@sku.upc}" disa开发者_JAVA技巧bled="disabled"/></p>
Now that looks "ok", but has several problems:
- It seems like too much typing. There must be a simpler way. I've Googled and searched forever, and I can't figure it out.
- Disabled fields can't be selected, so the user can't highlight the UPC and copy it to the clipboard
- I don't like the direct class references. Major hack.
Any ideas?
Usually when I do this, I do not display the data in the form - otherwise I run into the "butt-ugly" issue that you ran into. I usually just write it directly to the page, or put it in a span
or label
tag.
%label UPC:
%label= @object.upc
精彩评论