3

I'm trying to use deform as part of pyramid and have no trouble getting fully editable or fully read-only forms, but I can't seem to find a way of creating a read-only text input field. The following code does not do what I want, but I think you should be able to see what I'm trying to do:

class UserSchema(colander.MappingSchema):
    first_name = colander.SchemaNode(colander.String())
    last_name = colander.SchemaNode(colander.String())
    username = colander.SchemaNode(colander.String())
    password = colander.SchemaNode(colander.String())
    email = colander.SchemaNode(colander.String(), validator=colander.Email())
    organization_name = colander.SchemaNode(colander.String(), widget=deform.widget.TextInputWidget(readonly=True))
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
d0nut
  • 610
  • 5
  • 5

1 Answers1

4

Use the readonly template:

organization_name = colander.SchemaNode(colander.String(), missing='', widget=deform.widget.TextInputWidget(template='readonly/textinput'))

You have to define a missing value, otherwise the validation fails.

Deform version 0.9.6+:

Deform has been updated since and the readonly keyword argument should work as expected.

tuomur
  • 6,888
  • 34
  • 37
  • 1
    I think passing [`readonly`](http://docs.pylonsproject.org/projects/deform/en/latest/api.html?highlight=readonly#module-deform.widget) param to widget is preferred. Also see [Dont Validate Readonly Fields](http://deformdemo.repoze.org/readonly_value_nonvalidation/) – Piotr Dobrogost Feb 21 '16 at 21:11