Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make a deform/colander form field read-only/disabled?

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))
like image 906
d0nut Avatar asked Nov 05 '25 12:11

d0nut


1 Answers

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.

like image 98
tuomur Avatar answered Nov 08 '25 10:11

tuomur