Files
alamin-br 59da1eb2da feat: rich content in form view descriptions (#1851) (#5707)
* feat: rich text editor for form field description (creator)

* feat: render form field description as rich text (respondent)

* feat: rich text editor for form description (creator)

* feat: render form description as rich text (respondent)

Renders the form-level description read-only via RichTextEditor in
FormViewModeForm.vue (the public standard form), matching the field
description treatment from FormPageField.

FormViewModeSurvey.vue was checked and has no separate form-level
description/title render at all (it goes straight to fields), so no
change was needed there.

* docs: changelog for rich form descriptions (#1851)

* fix: only save form description after an actual edit

saveDescription ran on every editor blur and compared tiptap's
normalized markdown against the raw stored value, so clicking into
a legacy plain-text description (with chars like *, #, %) and away
without editing silently rewrote the stored value. Add a dirty flag
set only by update:modelValue (real edits) so blur without an edit
is a no-op.

Also drops the unused editor-class attribute on the description
RichTextEditor (no matching SCSS rule).

* perf: only mount field description editor when needed (v-if)

* fix: preserve in-progress description edit on external update; add e2e coverage

* fix: click-to-edit toggle for form descriptions; fix cursor reset

Replace the always-editable inline RichTextEditor on the form builder with a
shared FormViewDescription component that renders read-only markdown and mounts
the editor only while editing, behind an edit pencil (matching title/submit).

- Restores the edit affordance that regressed vs the old Editable.
- Passes model-value one-way and reads markdown back on blur, so typing after
  moving the cursor no longer resets to the end.
- No floating menu lingers on the form once editing stops.
- Removes the dirty/save-on-blur logic duplicated across FormViewField and
  FormViewModePreviewForm.

* test: cover form description toggle and save-on-blur

* fix: keep description editor menu stuck to cursor line on scroll

Pass the form preview's scroll container (.form-view__preview) to the editor so
its floating/bubble menu tracks the cursor line while the page scrolls, instead
of falling back to the editor's own non-scrolling root.

* Address PR review feedback (#5707)

- Route public form description render sites through FormViewDescription
- Pass scroll container as a resolver prop instead of a closest() lookup
- Wrap long unbroken words in form and field descriptions
- Use palette color variable for the description placeholder

* fix: clamp form description containers to the form column

The flex editor wrapper inside the inline-block description containers
made them shrink-to-fit their max-content width, letting long words
escape the form column on the public form.
2026-07-17 17:40:40 +02:00

82 lines
2.2 KiB
Vue

<template>
<div class="form-view__field-wrapper">
<div class="form-view__field">
<div class="form-view__field-inner">
<div class="form-view__field-name">
{{ field.name }}
<span v-if="field.required" class="form-view__field-required">*</span>
</div>
<div v-if="field.description" class="form-view__field-description">
<FormViewDescription
:value="field.description"
read-only
></FormViewDescription>
</div>
<component
:is="selectedFieldComponent.component"
:key="field.field.id"
ref="field"
:workspace-id="0"
:slug="slug"
:field="field.field"
:value="value"
:read-only="false"
:required="field.required"
:touched="field._.touched"
v-bind="selectedFieldComponent.properties"
@update="$emit('input', $event)"
@touched="field._.touched = true"
/>
</div>
</div>
</div>
</template>
<script>
import FieldContext from '@baserow/modules/database/components/field/FieldContext'
import FormViewDescription from '@baserow/modules/database/components/view/form/FormViewDescription'
import { DEFAULT_FORM_VIEW_FIELD_COMPONENT_KEY } from '@baserow/modules/database/constants'
export default {
name: 'FormPageField',
components: { FieldContext, FormViewDescription },
props: {
slug: {
type: String,
required: true,
},
value: {
required: true,
validator: () => true,
},
field: {
type: Object,
required: true,
},
},
emits: ['focussed', 'input'],
computed: {
selectedFieldComponent() {
const components = this.$registry
.get('field', this.field.field.type)
.getFormViewFieldComponents(this.field.field, this)
return Object.prototype.hasOwnProperty.call(
components,
this.field.field_component
)
? components[this.field.field_component]
: components[DEFAULT_FORM_VIEW_FIELD_COMPONENT_KEY]
},
},
methods: {
focus() {
this.$el.scrollIntoView({ behavior: 'smooth' })
this.$emit('focussed')
},
isValid() {
return this.$refs.field.isValid()
},
},
}
</script>