[SOLVED] Use (or simulate) TextLine instead of Text widget on Description

I want 'Description' to show as TextLine / 'just one line', Is it possible to do this in updateWidgets or updateFields (or do I need to 'fake it' with CSS). I tried versions of the below (without luck)

def updateFields(self):
    super(XXXXXAddForm, self).updateFields()
    #self.fields['IDublinCore.description'].field = "zope.schema._bootstrapfields.TextLine" # or skip _bootstrapfields



def updateWidgets(self):
    super(XXXXXXAddForm, self).updateWidgets()
    #self.widgets['IDublinCore.description'].something = 'xxxx'
    ##self.fields['IDublinCore.description'].widgetFactory =

Here's an approach that might help you overriding a different template for a specific field with getSpecification(IDublinCore["description"]) Z3c.form Display Template override, RelationList/RelatedItemsFieldWidget - #3 by jensens

Thanks.

So, instead of changing the widget, I changed the template, as described here:

http://plone-documentation.s3-website-us-east-1.amazonaws.com/latest/en/develop/plone/forms/z3c.form.html#setting-widget-templates


Note: If following the docs you might need to install zope.app.pagetemplate (I am not sure if from zope.app.pagetemplate import ViewPageTemplateFile as Z3ViewPageTemplateFile should be changed for Plone 6 )

Update: Use from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile as Z3ViewPageTemplateFile

For reference, code could be:

#from zope.app.pagetemplate import ViewPageTemplateFile as Z3ViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile as Z3ViewPageTemplateFile

class CompanyInformationAddForm(DefaultAddForm):
    portal_type = "company"

def __init__(self, context, request):
    super(CompanyInformationAddForm, self).__init__(context, request)

def updateWidgets(self):
    super(CompanyInformationAddForm, self).updateWidgets()
    self.widgets['IDublinCore.description'].label = 'Full Company Name'
    self.widgets['IDublinCore.description'].template = Z3ViewPageTemplateFile("description_template.pt")

zope.app.pagetemplate is deprecated ... use

from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile

instead.

This piece of documentation should also be updated and moved to Forms – Classic UI — Plone Documentation v6.0 :face_with_monocle: