Setting the size of a zope.formlib's schema html input
Hello, This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer. I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield? Take this as example: Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True) Is there an attribute like size or something? Thanks in advance, Marcelo.
On 2008-04-07 03:41:34 +0200, "Marcelo de Moraes Serpa" <celoserpa@gmail.com> said:
Hello,
This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer.
I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield?
Take this as example:
Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True)
Is there an attribute like size or something?
No, use CSS for layout. :) You could also use a custom widget which has a different size, but CSS might be the more correct separation. Regards, -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
Previously Christian Zagrodnick wrote:
On 2008-04-07 03:41:34 +0200, "Marcelo de Moraes Serpa" <celoserpa@gmail.com> said:
Hello,
This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer.
I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield?
Take this as example:
Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True)
Is there an attribute like size or something?
No, use CSS for layout. :)
That depends on the type of input you want to influence. For text <input> elements the size attribute indicates the maximum number of characters a user can input in the field, and you can not control that using CSS. Often you also want to put a different CSS class or id on the different type of <input> fields. You do not want your checkboxes to be just as wide as your text input fields! Wichert. -- Wichert Akkerman <wichert@wiggy.net> It is simple to make things. http://www.wiggy.net/ It is hard to make things simple.
On 2008-04-07 09:25:28 +0200, Wichert Akkerman <wichert@wiggy.net> said:
Previously Christian Zagrodnick wrote:
On 2008-04-07 03:41:34 +0200, "Marcelo de Moraes Serpa" <celoserpa@gmail.com> said:
Hello,
This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer.
I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield?
Take this as example:
Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True)
Is there an attribute like size or something?
No, use CSS for layout. :)
That depends on the type of input you want to influence. For text <input> elements the size attribute indicates the maximum number of characters a user can input in the field, and you can not control that using CSS.
Well, okay. But still this information must not be put into the schema/interface but in the form.
Often you also want to put a different CSS class or id on the different type of <input> fields. You do not want your checkboxes to be just as wide as your text input fields!
a) input[type="text"] b) You should have the widget id/name as id on the input field or some containing div. Regards, -- Christian Zagrodnick gocept gmbh & co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon. +49 345 12298894 · fax. +49 345 12298891
Previously Christian Zagrodnick wrote:
On 2008-04-07 09:25:28 +0200, Wichert Akkerman <wichert@wiggy.net> said:
That depends on the type of input you want to influence. For text <input> elements the size attribute indicates the maximum number of characters a user can input in the field, and you can not control that using CSS.
Well, okay. But still this information must not be put into the schema/interface but in the form.
Often you also want to put a different CSS class or id on the different type of <input> fields. You do not want your checkboxes to be just as wide as your text input fields!
a) input[type="text"]
IE doesn't support that.
b) You should have the widget id/name as id on the input field or some containing div.
ids are very cumbersome - you don't want to put list all ids for all forms in your CSS. That's what classes are for. Wichert. -- Wichert Akkerman <wichert@wiggy.net> It is simple to make things. http://www.wiggy.net/ It is hard to make things simple.
On Apr 6, 2008, at 9:41 PM, Marcelo de Moraes Serpa wrote:
Hello,
This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer.
I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield?
Take this as example:
Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True)
Is there an attribute like size or something?
Someone (you?) asked this in IRC. Schema's (and schema fields) are for specification, not presentation. (Yes, the title and description are used for presentation by default.) If you want to provide finer control over presentation, provide custom widget in the form field definition. (It might be nice if zope.formlib.Field provided the ability to provide widget data without having to specify the widget.) Jim -- Jim Fulton Zope Corporation
Thank you all for the replies! I wouldn't like to use CSS since I would like a "self-contained" form - all the data necessary to built the form would be in the schema. I think that the size of the text inputs, though being presentational in nature, in this case are **very** specific to the form and vary depending on the semantics of the fields, so, I don't think moving this data to a CSS would be the best option. Could someone show me an example of defining a widget to set the size of the rendered input? Marcelo. On Mon, Apr 7, 2008 at 8:10 AM, Jim Fulton <jim@zope.com> wrote:
On Apr 6, 2008, at 9:41 PM, Marcelo de Moraes Serpa wrote:
Hello,
This might sound lik a stupid question, but I couldn't find any simple solution or answer for this anywhere else, so hopefully someone in this list knows the answer.
I'm using zope.formlib to generate a simple contact form. It is simple and effective. But the framework complicates for simple things such as setting the size of a textfield. I don't want all the textfields to be of the same size - I want that, depending on the field, the size of the html input will vary. And that's exactly what I couldn't do as of yet. Does anyone know how could I set the size of a textfield?
Take this as example:
Telefone = schema.TextLine(title=_(u"Telefone para Contato"), required=True)
Is there an attribute like size or something?
Someone (you?) asked this in IRC.
Schema's (and schema fields) are for specification, not presentation. (Yes, the title and description are used for presentation by default.)
If you want to provide finer control over presentation, provide custom widget in the form field definition. (It might be nice if zope.formlib.Field provided the ability to provide widget data without having to specify the widget.)
Jim
-- Jim Fulton Zope Corporation
Could someone show me an example of defining a widget to set the size of the rendered input?
Marcelo, here's what I did: class PromosEditForm(EditForm): """An edit form to modify promo selection fields.""" form_fields = form.FormFields(IContentPromoFields) def setUpWidgets(self, ignore_request=False): self.adapters = { IContentPromoFields:ContentPromoFieldsAdapter(self.context) } self.widgets = form.setUpEditWidgets( self.form_fields, self.prefix, self.context, self.request, adapters=self.adapters, ignore_request=ignore_request ) self.label = "..." self.description = """\ ... """ self.widgets['global_promos'].size = 5 etc... I too would like to see an example of a full custom widget. For example I'd like to use an AT InOut-style dual list widget.
participants (5)
-
Christian Zagrodnick -
Jim Fulton -
Marcelo de Moraes Serpa -
Simon Michael -
Wichert Akkerman