File tree Expand file tree Collapse file tree 8 files changed +44
-8
lines changed Expand file tree Collapse file tree 8 files changed +44
-8
lines changed Original file line number Diff line number Diff line change 12
12
"input-type-text" : " Input (Text)" ,
13
13
"input-type-link" : " Input (Link)" ,
14
14
"input-type-number" : " Input (Number)" ,
15
+ "input-type-date" : " Input (Date)" ,
15
16
"input-type-select" : " Select" ,
17
+ "input-type-select-multi" : " Select Multiple" ,
16
18
"select-options" : " Options" ,
17
19
"select-options-help" : " Add one option per line for the select element" ,
18
20
"minimum-reputation" : " Minimum reputation" ,
Original file line number Diff line number Diff line change 213
213
"custom-user-field-select-value-invalid" : " Custom field selected option is invalid, %1" ,
214
214
"custom-user-field-invalid-link" : " Custom field link is invalid, %1" ,
215
215
"custom-user-field-invalid-number" : " Custom field number is invalid, %1" ,
216
+ "custom-user-field-invalid-date" : " Custom field date is invalid, %1" ,
216
217
"invalid-custom-user-field" : " Invalid custom user field, \" %1\" is already used by NodeBB" ,
217
218
"post-already-flagged" : " You have already flagged this post" ,
218
219
"user-already-flagged" : " You have already flagged this user" ,
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ define('admin/manage/user/custom-fields', [
69
69
label : '[[global:save]]' ,
70
70
callback : function ( ) {
71
71
const formData = modal . find ( 'form' ) . serializeObject ( ) ;
72
- if ( formData . type === 'select' ) {
72
+ if ( formData . type === 'select' || formData . type === 'select-multi' ) {
73
73
formData . selectOptionsFormatted = formData [ 'select-options' ] . trim ( ) . split ( '\n' ) . join ( ', ' ) ;
74
74
}
75
75
@@ -91,7 +91,7 @@ define('admin/manage/user/custom-fields', [
91
91
modal . find ( '#type-select' ) . on ( 'change' , function ( ) {
92
92
const type = $ ( this ) . val ( ) ;
93
93
modal . find ( `[data-input-type]` ) . addClass ( 'hidden' ) ;
94
- modal . find ( `[data-input-type=" ${ type } " ]` ) . removeClass ( 'hidden' ) ;
94
+ modal . find ( `[data-input-type- ${ type } ]` ) . removeClass ( 'hidden' ) ;
95
95
} ) ;
96
96
97
97
modal . find ( '#icon-select' ) . on ( 'click' , function ( ) {
Original file line number Diff line number Diff line change @@ -46,8 +46,18 @@ define('forum/account/edit', [
46
46
const els = $ ( '[component="group/badge/list"] [component="group/badge/item"][data-selected="true"]' ) ;
47
47
return els . map ( ( i , el ) => $ ( el ) . attr ( 'data-value' ) ) . get ( ) ;
48
48
}
49
+ const editForm = $ ( 'form[component="profile/edit/form"]' ) ;
50
+ const userData = editForm . serializeObject ( ) ;
51
+
52
+ // stringify multi selects
53
+ editForm . find ( 'select[multiple]' ) . each ( ( i , el ) => {
54
+ const name = $ ( el ) . attr ( 'name' ) ;
55
+ if ( userData [ name ] && ! Array . isArray ( userData [ name ] ) ) {
56
+ userData [ name ] = [ userData [ name ] ] ;
57
+ }
58
+ userData [ name ] = JSON . stringify ( userData [ name ] || [ ] ) ;
59
+ } ) ;
49
60
50
- const userData = $ ( 'form[component="profile/edit/form"]' ) . serializeObject ( ) ;
51
61
userData . uid = ajaxify . data . uid ;
52
62
userData . groupTitle = userData . groupTitle || '' ;
53
63
userData . groupTitle = JSON . stringify ( getGroupSelection ( ) ) ;
Original file line number Diff line number Diff line change @@ -144,14 +144,23 @@ helpers.getCustomUserFields = async function (userData) {
144
144
} ) ;
145
145
146
146
fields . forEach ( ( f ) => {
147
+ let userValue = userData [ f . key ] ;
148
+ if ( f . type === 'select-multi' && userValue ) {
149
+ userValue = JSON . parse ( userValue || '[]' ) ;
150
+ }
147
151
f [ 'select-options' ] = f [ 'select-options' ] . split ( '\n' ) . filter ( Boolean ) . map (
148
152
opt => ( {
149
153
value : opt ,
150
- selected : opt === userData [ f . key ] ,
154
+ selected : Array . isArray ( userValue ) ?
155
+ userValue . includes ( opt ) :
156
+ opt === userValue ,
151
157
} )
152
158
) ;
153
- if ( userData [ f . key ] ) {
154
- f . value = validator . escape ( String ( userData [ f . key ] ) ) ;
159
+ if ( userValue ) {
160
+ if ( Array . isArray ( userValue ) ) {
161
+ userValue = userValue . join ( ', ' ) ;
162
+ }
163
+ f . value = validator . escape ( String ( userValue ) ) ;
155
164
}
156
165
} ) ;
157
166
return fields ;
Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ module.exports = function (User) {
113
113
throw new Error ( tx . compile (
114
114
'error:custom-user-field-invalid-number' , field . name
115
115
) ) ;
116
+ } else if ( value && type === 'input-date' && ! validator . isDate ( value ) ) {
117
+ throw new Error ( tx . compile (
118
+ 'error:custom-user-field-invalid-date' , field . name
119
+ ) ) ;
116
120
} else if ( value && field . type === 'input-link' && ! validator . isURL ( String ( value ) ) ) {
117
121
throw new Error ( tx . compile (
118
122
'error:custom-user-field-invalid-link' , field . name
@@ -124,6 +128,14 @@ module.exports = function (User) {
124
128
'error:custom-user-field-select-value-invalid' , field . name
125
129
) ) ;
126
130
}
131
+ } else if ( field . type === 'select-multi' ) {
132
+ const opts = field [ 'select-options' ] . split ( '\n' ) . filter ( Boolean ) ;
133
+ const values = JSON . parse ( value || '[]' ) ;
134
+ if ( ! Array . isArray ( values ) || ! values . every ( value => opts . includes ( value ) ) ) {
135
+ throw new Error ( tx . compile (
136
+ 'error:custom-user-field-select-value-invalid' , field . name
137
+ ) ) ;
138
+ }
127
139
}
128
140
}
129
141
} ) ;
Original file line number Diff line number Diff line change 35
35
<td class =" text-nowrap" >{ {{ if ./icon } }}<i class =" text-muted { ./icon} " ></i > { {{ end } }}{ ./name} </td >
36
36
<td >
37
37
{ ./type}
38
- { {{ if (./type == " select" ) } }}
38
+ { {{ if (( ./type == " select" ) || (./type == " select-multi " ) ) } }}
39
39
<div class =" text-muted" >
40
40
({ ./selectOptionsFormatted} )
41
41
</div >
Original file line number Diff line number Diff line change 5
5
<option value =" input-text" { { { if (type == " input-text" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-text]]</option >
6
6
<option value =" input-link" { { { if (type == " input-link" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-link]]</option >
7
7
<option value =" input-number" { { { if (type == " input-number" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-number]]</option >
8
+ <option value =" input-date" { { { if (type == " input-date" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-date]]</option >
8
9
<option value =" select" { { { if (type == " select" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-select]]</option >
10
+ <option value =" select-multi" { { { if (type == " select-multi" ) } } } selected{{{ end }}} >[[admin/manage/user-custom-fields:input-type-select-multi]]</option >
9
11
</select >
10
12
</div >
11
13
33
35
<p class =" form-text" >[[admin/manage/user-custom-fields:minimum-reputation-help]]</p >
34
36
</div >
35
37
36
- <div class =" mb-3 { { { if (type != " select" ) } } } hidden{ { { end } } } " data-input-type = " select" >
38
+ <div class =" mb-3 { { { if (( type != " select" ) && (type != " select-multi " )) } } } hidden{ { { end } } } " data-input-type data-input-type- select data-input-type-select-multi >
37
39
<label class =" form-label" >[[admin/manage/user-custom-fields:select-options]]</label >
38
40
<textarea class =" form-control" name =" select-options" rows =" 6" >{ ./select-options} </textarea >
39
41
<p class =" form-text" >[[admin/manage/user-custom-fields:select-options-help]]</p >
You can’t perform that action at this time.
0 commit comments