Skip to content

Node.js based forum software built for the modern web

feat: allow selecting empty for custom selects

Barış Soner Uşaklıbe62ae24ade1
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index 4c289e5007..53ecea8534 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -194,7 +194,11 @@ helpers.getCustomUserFields = async function (callerUID, userData) {
if (f.type === 'input-link' && userValue) {
f.linkValue = validator.escape(String(userValue.replace('http://', '').replace('https://', '')));
}
- f['select-options'] = (f['select-options'] || '').split('\n').filter(Boolean).map(
+ f['select-options'] = (f['select-options'] || '').split('\n').filter(Boolean);
+ if (f.type === 'select') {
+ f['select-options'].unshift('');
+ }
+ f['select-options'] = f['select-options'].map(
opt => ({
value: opt,
selected: Array.isArray(userValue) ?
diff --git a/src/user/profile.js b/src/user/profile.js
index 40a0d3bc99..c150675d6a 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -127,7 +127,7 @@ module.exports = function (User) {
));
} else if (field.type === 'select') {
const opts = field['select-options'].split('\n').filter(Boolean);
- if (!opts.includes(value)) {
+ if (!opts.includes(value) && value !== '') {
throw new Error(tx.compile(
'error:custom-user-field-select-value-invalid', field.name
));