feat: allow selecting empty for custom selects

closes #13101
This commit is contained in:
Barış Soner Uşaklı
2025-01-30 10:22:45 -05:00
parent ef5ae00652
commit be62ae24ad
2 changed files with 6 additions and 2 deletions

View File

@@ -194,7 +194,11 @@ helpers.getCustomUserFields = async function (callerUID, userData) {
if (f.type === 'input-link' && userValue) { if (f.type === 'input-link' && userValue) {
f.linkValue = validator.escape(String(userValue.replace('http://', '').replace('https://', ''))); 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 => ({ opt => ({
value: opt, value: opt,
selected: Array.isArray(userValue) ? selected: Array.isArray(userValue) ?

View File

@@ -127,7 +127,7 @@ module.exports = function (User) {
)); ));
} else if (field.type === 'select') { } else if (field.type === 'select') {
const opts = field['select-options'].split('\n').filter(Boolean); const opts = field['select-options'].split('\n').filter(Boolean);
if (!opts.includes(value)) { if (!opts.includes(value) && value !== '') {
throw new Error(tx.compile( throw new Error(tx.compile(
'error:custom-user-field-select-value-invalid', field.name 'error:custom-user-field-select-value-invalid', field.name
)); ));