@@ -18,7 +18,7 @@ import { FeedbackBox } from './components/Feedback';
1818import * as hooks from './hooks' ;
1919import { ProblemTypeKeys } from '../../../../../data/constants/problem' ;
2020import ExpandableTextArea from '../../../../../sharedComponents/ExpandableTextArea' ;
21- import { answerRangeFormatRegex , numericRegex } from '../../../data/OLXParser' ;
21+ import { answerRangeFormatRegex } from '../../../data/OLXParser' ;
2222
2323const AnswerOption = ( {
2424 answer,
@@ -28,6 +28,7 @@ const AnswerOption = ({
2828 const dispatch = useDispatch ( ) ;
2929
3030 const problemType = useSelector ( selectors . problem . problemType ) ;
31+ const isNumericInputValid = useSelector ( selectors . problem . isNumericInputValid ) ;
3132 const images = useSelector ( selectors . app . images ) ;
3233 const isLibrary = useSelector ( selectors . app . isLibrary ) ;
3334 const learningContextId = useSelector ( selectors . app . learningContextId ) ;
@@ -53,10 +54,6 @@ const AnswerOption = ({
5354 const cleanedValue = value . replace ( / ^ \s + | \s + $ / g, '' ) ;
5455 return ! cleanedValue . length || answerRangeFormatRegex . test ( cleanedValue ) ;
5556 } ;
56- const validateAnswerNumeric = ( value ) => {
57- const cleanedValue = ( value ?? '' ) . trim ( ) ;
58- return ! cleanedValue . length || numericRegex . test ( cleanedValue ) ;
59- } ;
6057
6158 const getInputArea = ( ) => {
6259 if ( [ ProblemTypeKeys . SINGLESELECT , ProblemTypeKeys . MULTISELECT ] . includes ( problemType ) ) {
@@ -74,9 +71,8 @@ const AnswerOption = ({
7471 ) ;
7572 }
7673 if ( problemType !== ProblemTypeKeys . NUMERIC || ! answer . isAnswerRange ) {
77- const isValidValue = validateAnswerNumeric ( answer . title ) ;
7874 return (
79- < Form . Group isInvalid = { ! isValidValue } >
75+ < Form . Group isInvalid = { ! isNumericInputValid } >
8076 < Form . Control
8177 as = "textarea"
8278 className = "answer-option-textarea text-gray-500 small"
@@ -87,7 +83,7 @@ const AnswerOption = ({
8783 placeholder = { intl . formatMessage ( messages . answerTextboxPlaceholder ) }
8884
8985 />
90- { ! isValidValue && (
86+ { ! isNumericInputValid && (
9187 < Form . Control . Feedback type = "invalid" >
9288 < FormattedMessage { ...messages . answerNumericErrorText } />
9389 </ Form . Control . Feedback >
0 commit comments