Skip to content

Commit df54c0d

Browse files
authored
Merge pull request #287 from amichaelyu/word_counter_fix
fixed wordCount
2 parents 2dbfee9 + 4eff688 commit df54c0d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/FormPage/FormPage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const TextareaWordCountingWidget = (props) => {
119119
} = props;
120120

121121
const showWordCount = !!schema.word_count;
122-
const wordCount = value ? value.split(/\s+/g).length : 0;
122+
const wordCount = value ? value.split(/[\s]+/).filter(el => el !== '').length : 0;
123123

124124
const _onChange = ({ target: { value } }) => {
125125
return onChange(value === "" ? options.emptyValue : value);
@@ -183,7 +183,7 @@ function validate(formData, errors, schema) {
183183
.filter((key) => !!schema.properties[key].word_count)
184184
.forEach((key) => {
185185
const wordCount = schema.properties[key].word_count;
186-
if (formData[key] && formData[key].split(/\s+/g).length > wordCount) {
186+
if (formData[key] && formData[key].split(/[\s]+/).filter(el => el !== '').length > wordCount) {
187187
errors[key].addError(`Response cannot exceed ${wordCount} words`);
188188
}
189189
});
@@ -279,4 +279,4 @@ export default (props: IFormPageProps) => {
279279
)}
280280
</Form>
281281
);
282-
};
282+
};

0 commit comments

Comments
 (0)