Skip to content

Commit 10f131c

Browse files
fix 3634 - prevent adding duplicate skills
1 parent 2206419 commit 10f131c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/projects/detail/components/SkillsQuestion/SkillsQuestion.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,20 @@ class SkillsQuestion extends React.Component {
100100

101101
// if user enter only ' ' or ';' we should clean it to not allow
102102
if (indexOfSpace === 0 || indexOfSemiColon === 0 ) {
103-
return ''
103+
return value.replace(' ', '').replace(';', '')
104104
}
105105

106106
if (indexOfSemiColon >= 1 ) {
107+
const newValue = value.replace(';', '').trim()
107108
const currentValues = getValue()
108-
this.handleChange([...currentValues, { name: value.substring(0, value.length -1) }])
109-
// this is return empty to nullify value post processing
110-
return ''
109+
if (!_.some(currentValues, v => v && v.name === newValue)) {
110+
this.handleChange([...currentValues, { name: newValue}])
111+
// this is return empty to nullify value post processing
112+
return ''
113+
} else {
114+
// don't allow semicolon for duplicate values
115+
return value.replace(';', '')
116+
}
111117
}
112118

113119
this.setState({ customOptionValue: value })
@@ -172,7 +178,7 @@ class SkillsQuestion extends React.Component {
172178
placeholder="Start typing a skill then select from the list"
173179
value={selectGroupValues}
174180
getOptionLabel={(option) => option.name || ''}
175-
getOptionValue={(option) => option.name || ''}
181+
getOptionValue={(option) => (option.name || '').trim()}
176182
onInputChange={this.onSelectType}
177183
onChange={(val) => {
178184
this.handleChange(_.union(val, checkboxGroupValues))

0 commit comments

Comments
 (0)