Browse Source

fix: support both wrapped or unwrapped cdf for select columns

pull/6584/head
mertmit 1 year ago
parent
commit
92841bf1ae
  1. 76
      packages/nocodb/src/services/columns.service.ts

76
packages/nocodb/src/services/columns.service.ts

@ -371,18 +371,38 @@ export class ColumnsService {
);
if (colBody.cdf) {
if (colBody.uidt === UITypes.SingleSelect) {
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${colBody.cdf}' is not a select option.`,
);
}
} else {
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
try {
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
`Default value '${colBody.cdf}' is not a select option.`,
);
}
} catch (e) {
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, '');
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${colBody.cdf}' is not a select option.`,
);
}
}
} else {
try {
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
);
}
}
} catch (e) {
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, '');
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
);
}
}
}
}
@ -1146,18 +1166,38 @@ export class ColumnsService {
// Handle default values
if (colBody.cdf) {
if (colBody.uidt === UITypes.SingleSelect) {
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${colBody.cdf}' is not a select option.`,
);
}
} else {
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
try {
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
`Default value '${colBody.cdf}' is not a select option.`,
);
}
} catch (e) {
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, '');
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${colBody.cdf}' is not a select option.`,
);
}
}
} else {
try {
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
);
}
}
} catch (e) {
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, '');
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) {
NcError.badRequest(
`Default value '${cdf}' is not a select option.`,
);
}
}
}
}

Loading…
Cancel
Save