diff --git a/src/jsonschema_colander/meta.py b/src/jsonschema_colander/meta.py index 6371e77..b7ccc62 100644 --- a/src/jsonschema_colander/meta.py +++ b/src/jsonschema_colander/meta.py @@ -120,7 +120,9 @@ def __init__( self.label = label or name self.description = description self.required = required - self.readonly = self.fieldconf.get("readonly", False) + self.readonly = self.fieldconf.get( + 'readonly', self.config.get('readonly', False) + ) self.validators = validators if validators := self.fieldconf.get("validators"): self.validators.extend(validators) @@ -163,6 +165,8 @@ def get_factory(self): def get_widget(self, factory, options): if widget := default_widget_makers.get(factory): + if isinstance(widget, colander.deferred): + return widget if READONLY_WIDGET: return widget(readonly=self.readonly) return widget() diff --git a/src/jsonschema_colander/types.py b/src/jsonschema_colander/types.py index 16fda63..fee9995 100644 --- a/src/jsonschema_colander/types.py +++ b/src/jsonschema_colander/types.py @@ -10,7 +10,8 @@ try: import deform.widget string_widgets = { - "password": deform.widget.PasswordWidget + "password": deform.widget.PasswordWidget, + "textarea": deform.widget.TextAreaWidget } enum_widgets = { colander.String: deform.widget.SelectWidget, @@ -18,8 +19,7 @@ } except ImportError: string_widgets = {} - enum_widgets = { - } + enum_widgets = {} @converter.register('string') @@ -59,8 +59,15 @@ def get_widget(self, factory, options): """ if 'choices' in self.attributes: if widget := enum_widgets.get(factory): - return widget(values=self.attributes['choices']) + if isinstance(widget, colander.deferred): + return widget + return widget( + values=self.attributes['choices'], + readonly=self.readonly + ) elif widget := self.widgets.get(self.format): + if isinstance(widget, colander.deferred): + return widget if READONLY_WIDGET: return widget(readonly=self.readonly) return widget() @@ -175,7 +182,12 @@ def get_factory(self): def get_widget(self, factory, options): if 'choices' in self.attributes: if widget := enum_widgets.get(factory): - return widget(values=self.attributes['choices']) + if isinstance(widget, colander.deferred): + return widget + return widget( + values=self.attributes['choices'], + readonly=self.readonly + ) return super().get_widget(factory, options) def __call__(self):