@@ -19,6 +19,7 @@ import * as hooks from './hooks';
1919import { ProblemTypeKeys } from '../../../../../data/constants/problem' ;
2020import ExpandableTextArea from '../../../../../sharedComponents/ExpandableTextArea' ;
2121import { answerRangeFormatRegex } from '../../../data/OLXParser' ;
22+ import { useValidateInputBlock } from '../../../data/apiHooks' ;
2223
2324const AnswerOption = ( {
2425 answer,
@@ -28,12 +29,10 @@ const AnswerOption = ({
2829 const dispatch = useDispatch ( ) ;
2930
3031 const problemType = useSelector ( selectors . problem . problemType ) ;
31- const isNumericInputValid = useSelector ( selectors . problem . isNumericInputValid ) ;
3232 const images = useSelector ( selectors . app . images ) ;
3333 const isLibrary = useSelector ( selectors . app . isLibrary ) ;
3434 const learningContextId = useSelector ( selectors . app . learningContextId ) ;
3535 const blockId = useSelector ( selectors . app . blockId ) ;
36-
3736 const removeAnswer = hooks . removeAnswer ( { answer, dispatch } ) ;
3837 const setAnswer = hooks . setAnswer ( { answer, hasSingleAnswer, dispatch } ) ;
3938 const setAnswerTitle = hooks . setAnswerTitle ( {
@@ -45,6 +44,7 @@ const AnswerOption = ({
4544 const setSelectedFeedback = hooks . setSelectedFeedback ( { answer, hasSingleAnswer, dispatch } ) ;
4645 const setUnselectedFeedback = hooks . setUnselectedFeedback ( { answer, hasSingleAnswer, dispatch } ) ;
4746 const { isFeedbackVisible, toggleFeedback } = hooks . useFeedback ( answer ) ;
47+ const { data = { is_valid : true } , mutate } = useValidateInputBlock ( ) ;
4848
4949 const staticRootUrl = isLibrary
5050 ? `${ getConfig ( ) . STUDIO_BASE_URL } /library_assets/blocks/${ blockId } /`
@@ -72,18 +72,21 @@ const AnswerOption = ({
7272 }
7373 if ( problemType !== ProblemTypeKeys . NUMERIC || ! answer . isAnswerRange ) {
7474 return (
75- < Form . Group isInvalid = { ! isNumericInputValid } >
75+ < Form . Group isInvalid = { ! data ?. is_valid ?? true } >
7676 < Form . Control
7777 as = "textarea"
7878 className = "answer-option-textarea text-gray-500 small"
7979 autoResize
8080 rows = { 1 }
8181 value = { answer . title }
82- onChange = { setAnswerTitle }
82+ onChange = { ( e ) => {
83+ setAnswerTitle ( e ) ;
84+ mutate ( { title : e . target . value } ) ;
85+ } }
8386 placeholder = { intl . formatMessage ( messages . answerTextboxPlaceholder ) }
8487
8588 />
86- { ! isNumericInputValid && (
89+ { ( ! data ?. is_valid ?? true ) && (
8790 < Form . Control . Feedback type = "invalid" >
8891 < FormattedMessage { ...messages . answerNumericErrorText } />
8992 </ Form . Control . Feedback >
0 commit comments