@@ -19,41 +19,43 @@ const QuestionTextarea = ({ question, useForm }) => {
1919 formState : { errors }
2020 } = useForm
2121 const defaultRows = 5
22- const reg = {
23- ...question . registerConfig ,
24- pattern : new RegExp ( question . registerConfig . pattern ) ,
25- // By default is char count
26- minLength :
27- question . registerConfig . countType !== 'word' &&
28- question . registerConfig . minimumLen ,
29- maxLength :
30- question . registerConfig . countType !== 'word' &&
31- question . registerConfig . maximumLen ,
32- validate : {
33- minWordCount : ( v ) => {
34- if (
35- question . registerConfig . countType === 'word' &&
36- question . registerConfig . minimumLen
37- ) {
38- return (
39- v . trim ( ) . split ( / [ \s , . \n ] + / ) . length >=
40- question . registerConfig . minimumLen
41- )
42- } else return true
43- } ,
44- maxWordCount : ( v ) => {
45- if (
46- question . registerConfig . countType === 'word' &&
47- question . registerConfig . maximumLen
48- ) {
49- return (
50- v . trim ( ) . split ( / [ \s , . \n ] + / ) . length <=
51- question . registerConfig . maximumLen
52- )
53- } else return true
22+ const reg = question . registerConfig
23+ ? {
24+ ...question . registerConfig ,
25+ pattern : new RegExp ( question . registerConfig . pattern ) ,
26+ // By default is char count
27+ minLength :
28+ question . registerConfig . countType !== 'word' &&
29+ question . registerConfig . minimumLen ,
30+ maxLength :
31+ question . registerConfig . countType !== 'word' &&
32+ question . registerConfig . maximumLen ,
33+ validate : {
34+ minWordCount : ( v ) => {
35+ if (
36+ question . registerConfig . countType === 'word' &&
37+ question . registerConfig . minimumLen
38+ ) {
39+ return (
40+ v . trim ( ) . split ( / [ \s , . \n ] + / ) . length >=
41+ question . registerConfig . minimumLen
42+ )
43+ } else return true
44+ } ,
45+ maxWordCount : ( v ) => {
46+ if (
47+ question . registerConfig . countType === 'word' &&
48+ question . registerConfig . maximumLen
49+ ) {
50+ return (
51+ v . trim ( ) . split ( / [ \s , . \n ] + / ) . length <=
52+ question . registerConfig . maximumLen
53+ )
54+ } else return true
55+ }
56+ }
5457 }
55- }
56- }
58+ : { }
5759
5860 return (
5961 < div
@@ -87,8 +89,10 @@ const QuestionTextarea = ({ question, useForm }) => {
8789 name = { question . name }
8890 placeholder = { question . placeholder }
8991 defaultValue = { question . defaultValue }
90- maximumLen = { question . registerConfig . maximumLen }
91- countType = { question . registerConfig . countType }
92+ maximumLen = {
93+ question . registerConfig && question . registerConfig . maximumLen
94+ }
95+ countType = { question . registerConfig && question . registerConfig . countType }
9296 { ...register ( question . name , reg ) }
9397 />
9498 { errors [ question . name ] &&
0 commit comments