On Feb 5, 7:53 pm, Jonathan Lundell <[email protected]> wrote:
> On Feb 5, 2010, at 4:40 PM, mdipierro wrote:
>
> > On Feb 5, 4:24 pm, Jonathan Lundell <[email protected]> wrote:
> >> A couple of SQLFORM-related questions.
>
> >> 1. I'd like a wider string input field, and I'm not sure how to get it. 
> >> Unless there's an easier way, I was thinking I'd extend the string widget 
> >> to embed a size & maxlength. The manual mentions widget extension, but 
> >> there's no example (only an example of writing a new one).
>
> >> So: how to extend the string widget? And how to invoke the existing string 
> >> widget from FIELD with size/maxlength attributes? (And is there yet 
> >> another method I'm overlooking?)
>
> > in css
>
> > #table_field {
> >   width: 400px;
> > }
>
> Well, yeah, but that's semantically different from setting size/maxlength on 
> a text field. Can I pass the attributes to INPUT somehow?

You are wight.
form.element(_name='field')['size']=200

>
> And how do you extend an existing widget?
>
>
>
> >> 2. I have a table with a user ID, writable=False. In the SQLFORM, I'd like 
> >> to display it as the user's name or email address instead of the bare ID. 
> >> How?
>
> > This should be automatica if the referenced table has a format
> > attribute. Else set something like
>
> I don't find "format attribute" in the manual. Should I be looking for 
> something else?

That is one of the new features.

db.define_table('person',Field('name'),format='%(name)s')

format automatically sets the IS_IN_DB validator for all fields that
reference this table and sets the "represent" attribute of the
referencing fields to a lambda function that implements the format
representation.

format itself can be a lambda function:

db.define_table('person',Field('name'),format='%(name)s')
db.define_table('dog',Field('name'),Field('owner',db.person),
  format=lambda row: '%s of %s'% (row.name,row.owner.name))
db.define_table('vaccination',Field('name'),Field('dog',db.dog),
  format=lambda row: '%s to %s of %s' %
(row.name,row.dog.name,row.dog.owner.name))








>
>
>
> > db.referenced_table.id.represent=lambda id: db.referenced_table.
> > [id].name
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" 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/web2py?hl=en.

Reply via email to