Text box does not scale in custom form

151 views
Skip to first unread message

Gary

unread,
Nov 24, 2009, 9:44:58 PM11/24/09
to web2py-users
I expected the custom widget for strings to scale to the size of the
length specified in the ORM, but they all come out the same size - and
they're big.

Is there another place I should be entering something that helps me
with this? I've constructed a custom form using CRUD and the field
names are {{=form.custom.widget.fieldname}}.

Thanks in advance,
Gary

Gary

unread,
Nov 24, 2009, 10:00:13 PM11/24/09
to web2py-users
Sorry, missed the posting two down titled 'Length'.

That solved the problem, but is there a more eloquent way not using
JQuery?

Thadeus Burgess

unread,
Nov 24, 2009, 10:24:29 PM11/24/09
to web...@googlegroups.com
Use CSS.

You will have to edit web2py_ajax.html and remove the javascripts that alter field lengths.

In css

input {
    width: 150px;
    height: 25px;
    font-size: 1.5em;
   ...etc etc
}

OR reference by class name or ID

-Thadeus

mr.freeze

unread,
Nov 24, 2009, 10:30:16 PM11/24/09
to web2py-users
I personally don't agree with using javascript to set properties like
that. I remove these lines from web2py_ajax.html:

jQuery('input.string').attr('size',50);
jQuery('textarea.text').attr('cols',50).attr('rows',10);

Then use custom widgets or just set the properties if the form
elements directly:

form = SQLFORM(...)
txt = form.elements("textarea",_class="text")
for t in txt:
t['_cols'] = 10

Or with a widget:

def textarea_factory(**attr):
def fn(f,v):
return SQLFORM.widgets.text.widget(f,v,**attr)
return fn

form = SQLFORM.factory(Field('test','text',widget=textarea_factory
(_cols=40,_rows=15)))




db.table.field.widget = textarea_factory(_cols=10)

Thadeus Burgess

unread,
Nov 24, 2009, 10:33:04 PM11/24/09
to web...@googlegroups.com
CSS will always be the best route for this, since you are "designing" your forms. Leave the styling of your site to CSS, and the programming to web2py :)

The other benefit of this is, if you want to update the way your site looks, instead of having to edit lines of code, you just replace your CSS files.

-Thadeus

mr.freeze

unread,
Nov 24, 2009, 10:36:53 PM11/24/09
to web2py-users
Agreed. If you can achieve the desired effect with CSS it should be
the first choice. My examples should only be used if you need to
modify attributes.

mdipierro

unread,
Nov 25, 2009, 8:58:48 AM11/25/09
to web2py-users
Would you send me a patch to remove

jQuery('input.string').attr('size',50);
jQuery('textarea.text').attr('cols',50).attr('rows',10);

from web2py_ajax.html

that adds the relevant css in base.css?
Reply all
Reply to author
Forward
0 new messages