Wednesday, December 12, 2007

Tuesday, December 11, 2007

Adding classes/style to django form elements

The 'attrs' argument to the Widget class used with each particular
Field (the Widget is what actually renders the HTML) accepts a
dictionary which will become HTML attribute names and values. For
example:

username = forms.CharField(widget=forms.TextInput(attrs={'class': 'myclass'}))

will become:



the old forms default of having class attributes for each
input type (e.g. class=vTextField for type=text)

Sunday, December 09, 2007

populating select box from database ror

controller code looks something like:

class testController < ApplicationController

def test
@categories= Category.find_all
end

end

use
<%= options_from_collection_for_select @categories, 'id', 'name' %>
to populate the select box