diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py index f4d5f14f..ea8808e3 100644 --- a/tailbone/forms/core.py +++ b/tailbone/forms/core.py @@ -900,11 +900,17 @@ class Form(object): not for "readonly" fields. """ dform = self.make_deform_form() - field = dform[fieldname] - label = self.get_label(fieldname) - markdowns = self.get_field_markdowns() + field = dform[fieldname] if fieldname in dform else None + + include = bool(field) + if self.readonly or (not field and fieldname in self.readonly_fields): + include = True + if not include: + return if self.field_visible(fieldname): + label = self.get_label(fieldname) + markdowns = self.get_field_markdowns() # these attrs will be for the (*not* the widget) attrs = { @@ -912,15 +918,17 @@ class Form(object): } # add some magic for file input fields - if isinstance(field.schema.typ, deform.FileData): + if field and isinstance(field.schema.typ, deform.FileData): attrs['class_'] = 'file' # show helptext if present + # TODO: older logic did this only if field was *not* + # readonly, perhaps should add that back.. if self.has_helptext(fieldname): attrs['message'] = self.render_helptext(fieldname) # show errors if present - error_messages = self.get_error_messages(field) + error_messages = self.get_error_messages(field) if field else None if error_messages: # TODO: this surely can't be what we ought to do @@ -941,22 +949,16 @@ class Form(object): attrs.update(bfield_attrs) # render the field widget or whatever - html = field.serialize(use_buefy=True, - **self.get_renderer_kwargs(fieldname)) - html = HTML.literal(html) + if self.readonly or fieldname in self.readonly_fields: + html = self.render_field_value(fieldname) or HTML.tag('span') + elif field: + html = field.serialize(use_buefy=True, + **self.get_renderer_kwargs(fieldname)) + html = HTML.literal(html) # may need a complex label label_contents = [label] - # add 'configure' icon if allowed - if self.can_edit_help: - icon = HTML.tag('b-icon', size='is-small', pack='fas', - icon='cog') - icon = HTML.tag('a', title="Configure field", c=[icon], - **{'@click.prevent': "configureFieldInit('{}')".format(fieldname)}) - label_contents.append(HTML.literal('   ')) - label_contents.append(icon) - # add 'help' icon/tooltip if defined if markdowns.get(fieldname): icon = HTML.tag('b-icon', size='is-small', pack='fas', @@ -978,6 +980,16 @@ class Form(object): label_contents.append(HTML.literal('   ')) label_contents.append(tooltip) + # add 'configure' icon if allowed + if self.can_edit_help: + icon = HTML.tag('b-icon', size='is-small', pack='fas', + icon='cog') + icon = HTML.tag('a', title="Configure field", c=[icon], + **{'@click.prevent': "configureFieldInit('{}')".format(fieldname), + 'v-show': 'configureFieldsHelp'}) + label_contents.append(HTML.literal('   ')) + label_contents.append(icon) + # nb. must apply hack to get