1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-03-14 12:42:51 +00:00
bramw_baserow/web-frontend/modules/database/mixins/rowEditField.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2021-07-11 18:02:37 +00:00
import baseField from '@baserow/modules/database/mixins/baseField'
2020-05-11 17:27:35 +00:00
/**
* A mixin that can be used by a row edit modal component. It introduces the props that
* will be passed by the RowEditModalField component.
*/
export default {
2021-07-11 18:02:37 +00:00
mixins: [baseField],
2020-05-11 17:27:35 +00:00
props: {
2021-07-11 18:02:37 +00:00
readOnly: {
type: Boolean,
2020-05-11 17:27:35 +00:00
required: true,
},
/**
2021-07-11 18:02:37 +00:00
* Indicates if the value is required. If so, then an error is added when the
* value is not provided.
2020-05-11 17:27:35 +00:00
*/
2021-07-11 18:02:37 +00:00
required: {
type: Boolean,
2020-05-11 17:27:35 +00:00
required: false,
2021-07-11 18:02:37 +00:00
default: false,
2020-05-11 17:27:35 +00:00
},
2021-07-11 18:02:37 +00:00
/**
* Indicates if the input has been touched by the user. If not touched then the
* error messages are not displayed because that might be confusing for the
* user. By default this is set to true because that's expected in the row
* modal. When using it as a form that is first rendered in an empty state, then
* this value should be false.
*/
touched: {
2021-04-08 14:30:26 +00:00
type: Boolean,
2021-07-11 18:02:37 +00:00
required: false,
default: true,
},
2024-04-02 19:50:44 +00:00
rowIsCreated: {
type: Boolean,
required: false,
default: () => true,
},
2021-07-11 18:02:37 +00:00
},
methods: {
/**
* Extends the getValidationError and add the required error message if this
* field value is required.
*/
getValidationError(value) {
const error = baseField.methods.getValidationError.call(this, value)
if (this.required && error === null) {
const fieldType = this.$registry.get('field', this.field.type)
const empty = fieldType.isEmpty(this.field, value)
if (empty) {
return this.$t('error.requiredField')
2021-07-11 18:02:37 +00:00
}
}
return error
},
touch() {
if (!this.touched) {
this.$emit('touched')
}
2021-04-08 14:30:26 +00:00
},
2020-05-11 17:27:35 +00:00
},
}