And in the controller/view, you can use db.foo.height.represent = lambda v: 'xx feet yy inch zz fraction' to display it, therefore you need not depend on javascript.
On Jun6, 7:12am, MikeEllis <michael.f.el...@gmail.com> wrote: > Oops hit send by accident. > > so after the form.accepts(request.vars, session), you'll need code to > convert the feet, inches, and fractions to a double and stuff it into > the database. Some of the more experienced web2py users may have a > better way, but this approach is working for me. > > Cheers, > Mike > > On Jun 5, 7:08 pm, MikeEllis <michael.f.el...@gmail.com> wrote: > > > > > I've been using SQLFORM.factory() for cases where what's in the db > > needs to be presented to the user in a different format. The online > > book has some good examples. For your case, my first thought would be > > to define a function in the model that generates the form, e.g. > > > def fooform(): > > fields = [] > > ... > > fields.append('Feet', 'integer', ...) > > fields.append('Inches', 'integer', requires=IS_IN_SET(range(0-12))) > > fields.append('Fraction', 'string', requires=IS_IN_SET(["0", "1/4", > > "1/2", "3/4"])) > > ... > > return SQLFORM.factory(*fields) > > > Then in your controller, > > form = fooform() > > if form.accepts(): > > > form = fooform() > > if form.accepts(): > > > On Jun 4, 12:09 pm, Keith <ke...@setuplinux.com> wrote: > > > > I'm new to web2py and the I did this previously was with javascript > > > but I was hoping to avoid that this go around. > > > > In my database table I have a single field something like this below: > > > > db.define_table('foo', > > > Field('height', 'double'), > > > > In the controller/view I need to be able to translate that so when > > > viewing a record they see: > > > Feet, Inches, and Fractions of a Inch. > > > > When adding a record it would need to be a text field for feet and > > > drop down lists for inches and fractions of a inch. > > > > I know how to do that in javascript, but I don't like relying on > > > javascript if possible. I'm hoping there is a way to do this in the > > > controller or model. > > > > Thanks for any suggestions.