mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* fix(web-frontend): Show unnamed row label for empty linked rows in form dropdowns * fix: address reviewer comments on form link-row dropdown fix * fix(web-frontend): keep required validation passing when user picks an unnamed linked row * fix(web-frontend): reset the cache to prevent it from growing unboundedly * fix(web-frontend): enforce required form validation at the field-type level Required validation in the form submit path relied on each component's isValid(), which the duration field overrides with a touched-based check. An untouched empty required duration field therefore passed validation and the form submitted an empty value the backend rejected. Move the required check back to the field-type level via a new isEmptyForRequiredValidation(), which defaults to isEmpty but lets link_row use presence semantics (a picked row with an empty primary still counts as filled) without changing isEmpty, so the conditional-visibility filters keep treating that row as empty. Also generalise PaginatedDropdown so valueName accepts a function and select() emits the resolved item, which removes the fetchPage side effects (label injection and the rowLookup copy) and lets the single and multiple link-row components share a formViewLinkRowField mixin. * fix(web-frontend): align link_row empty semantics with the backend Replace isEmptyForRequiredValidation with a single isEmpty. A link_row is a many-to-many relation, so the backend treats it as empty only when no row is linked; the frontend's isEmpty was inheriting the base array check and reporting a picked empty-primary row as empty. Make isEmpty selection-based so the conditional-visibility filters and required form validation share one definition that matches the backend. * test(e2e): cover link_row behaviour on the public form Add e2e tests for the public form link_row field: the "unnamed row" label for empty-primary linked rows, an empty-primary pick revealing a show-when-not-empty field, client-side blocking of a required empty field, and a required link satisfied by an empty-primary row. Add form-view and row fixtures and a FormPage page object to support them. * refactor(web-frontend): tidy form link-row validation and row-value resolution Collapse the duplicated requiredField branches in the multiple link-row getValidationError into a single guard, document why it delegates to baseField (not rowEditField) to avoid a double required check, and extract the shared item/displayName resolution into resolveRowValue on the mixin so the explanatory comment lives in one place. No behaviour change; covered by existing form link-row unit tests. * refactor(e2e): merge createTable helpers and fix link_row isEmpty semantics Unify createTable/createTableWithData into a single createTable with an optional data argument, and treat a link_row value as empty only when every slot lacks a real id (some -> every), so a picked empty-primary row counts as a real selection. * fix(web-frontend): show required error for an untouched empty duration field The duration field only computed its error message while the user typed, so a required, untouched, empty field blocked form submission silently with no visible error. Fall back to the field-type validation in the duration mixin's getError so the required error renders on submit, and assert it in the e2e. * refactor(web-frontend): drop redundant duration isValid override isValid() now matches baseField's implementation exactly, and no intermediate mixin defines it, so the override is dead weight. * fix(web-frontend): guard duration form error slot with touched && !valid
74 lines
2.4 KiB
JavaScript
74 lines
2.4 KiB
JavaScript
import ViewService from '@baserow/modules/database/services/view'
|
|
|
|
/**
|
|
* Shared logic for the single (`FormViewFieldLinkRow`) and multiple
|
|
* (`FormViewFieldMultipleLinkRow`) form-view link-row components: how a related
|
|
* row is labelled in the dropdown and how a page of related rows is fetched.
|
|
*/
|
|
export default {
|
|
props: {
|
|
slug: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
/**
|
|
* In some cases, for example in the form view preview, we only want to fetch the
|
|
* first related rows after the user has opened the dropdown. This will prevent a
|
|
* race condition where the enabled state of the field might not yet been updated
|
|
* before we fetch the related rows. If the state has not yet been changed in the
|
|
* backend, it will result in an error.
|
|
*/
|
|
lazyLoad: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: false,
|
|
},
|
|
},
|
|
methods: {
|
|
/**
|
|
* The display label for a related row. Rows whose primary field is empty
|
|
* fall back to the same "unnamed row" label used in the grid, while
|
|
* placeholder slots (without a real row id) keep their empty value.
|
|
*/
|
|
rowDisplayName(row) {
|
|
if (row.value) {
|
|
return row.value
|
|
}
|
|
if (!Number.isInteger(row.id)) {
|
|
return row.value
|
|
}
|
|
return this.$t('functionnalGridViewFieldLinkRow.unnamed', {
|
|
value: row.id,
|
|
})
|
|
},
|
|
/**
|
|
* The value to store for a picked row. Prefer the original row value (e.g.
|
|
* '' for empty primary fields) so conditional visibility checks keep
|
|
* working, and fall back to the dropdown's display name only when the row
|
|
* couldn't be resolved (e.g. a pre-existing selection that isn't in the
|
|
* current results).
|
|
*/
|
|
resolveRowValue(item, displayName) {
|
|
return item ? item.value : displayName
|
|
},
|
|
/**
|
|
* Fetches a page of related rows for the dropdown. This is a pure
|
|
* pass-through: the dropdown derives the display label through `valueName`
|
|
* and hands the original row back on selection, so no copy of the data has
|
|
* to be kept here.
|
|
*/
|
|
fetchPage(page, search) {
|
|
const publicAuthToken =
|
|
this.$store.getters['page/view/public/getAuthToken']
|
|
return ViewService(this.$client).linkRowFieldLookup(
|
|
this.slug,
|
|
this.field.id,
|
|
page,
|
|
search,
|
|
100,
|
|
publicAuthToken
|
|
)
|
|
},
|
|
},
|
|
}
|