Implement unique constraint support (#4467)

* Allow creating unique fields

* Allow removing unique constriant

* Show unique constraint error as validation error in app
This commit is contained in:
Rijk van Zanten
2021-03-10 17:35:21 -05:00
committed by GitHub
parent 7569168e3e
commit 4248b187bb
7 changed files with 35 additions and 5 deletions

View File

@@ -54,7 +54,7 @@
<small class="note" v-if="field.meta && field.meta.note" v-html="marked(field.meta.note)" />
<small class="validation-error" v-if="validationError">
{{ $t(`validationError.${validationError.type}`, validationError) }}
{{ validationMessage }}
</small>
</div>
</template>
@@ -69,6 +69,7 @@ import FormFieldInterface from './form-field-interface.vue';
import { ValidationError } from './types';
import { getJSType } from '@/utils/get-js-type';
import { isEqual } from 'lodash';
import { i18n } from '@/lang';
export default defineComponent({
components: { FormFieldLabel, FormFieldMenu, FormFieldInterface },
@@ -133,7 +134,15 @@ export default defineComponent({
const { showRaw, rawValue } = useRaw();
return { isDisabled, marked, _value, emitValue, showRaw, rawValue };
const validationMessage = computed(() => {
if (props.validationError.code === 'RECORD_NOT_UNIQUE') {
return i18n.t('validationError.unique');
} else {
return i18n.t(`validationError.${props.validationError.type}`, props.validationError);
}
});
return { isDisabled, marked, _value, emitValue, showRaw, rawValue, validationMessage };
function emitValue(value: any) {
if (

View File

@@ -9,6 +9,7 @@ export type FormField = DeepPartial<Field> & {
};
export type ValidationError = {
code: string;
field: string;
type: FilterOperator;
valid?: number | string | (number | string)[];