Skip to content

Commit

Permalink
Merge pull request #287 from amichaelyu/word_counter_fix
Browse files Browse the repository at this point in the history
fixed wordCount
  • Loading branch information
connorff authored Nov 3, 2024
2 parents 2dbfee9 + 4eff688 commit df54c0d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/FormPage/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const TextareaWordCountingWidget = (props) => {
} = props;

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

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

0 comments on commit df54c0d

Please sign in to comment.