@@ -18,6 +18,17 @@ const EducationStep = ({ formData, onInputChange }) => {
1818 setActiveTab ( tabId ) ;
1919 } , [ ] ) ;
2020
21+ const validatePercentage = ( value ) => {
22+ const regex = / ^ ( \d { 0 , 3 } \. ? \d { 0 , 2 } ) % ? $ / ;
23+ return regex . test ( value ) ;
24+ } ;
25+
26+ const handlePercentageChange = ( subsection , field , value ) => {
27+ if ( value === '' || validatePercentage ( value ) ) {
28+ updateSubSection ( subsection , field , value ) ;
29+ }
30+ } ;
31+
2132 const validateYears = ( startYear , endYear , section ) => {
2233 if ( startYear && endYear ) {
2334 const start = parseInt ( startYear ) ;
@@ -217,7 +228,7 @@ const EducationStep = ({ formData, onInputChange }) => {
217228
218229 < div className = "relative" >
219230 < label className = "block text-sm font-medium text-gray-700 mb-1" >
220- Grade/ Percentage
231+ Percentage
221232 </ label >
222233 < div className = "relative" >
223234 < div className = "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" >
@@ -226,7 +237,7 @@ const EducationStep = ({ formData, onInputChange }) => {
226237 < input
227238 type = "text"
228239 value = { formData . education ?. schooling ?. grade || '' }
229- onChange = { ( e ) => updateSubSection ( 'schooling' , 'grade' , e . target . value ) }
240+ onChange = { ( e ) => handlePercentageChange ( 'schooling' , 'grade' , e . target . value ) }
230241 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
231242 placeholder = "e.g., 85% or A+"
232243 />
@@ -373,7 +384,7 @@ const EducationStep = ({ formData, onInputChange }) => {
373384 < input
374385 type = "text"
375386 value = { formData . education ?. college ?. eleventhGrade || '' }
376- onChange = { ( e ) => updateSubSection ( 'college' , 'eleventhGrade' , e . target . value ) }
387+ onChange = { ( e ) => handlePercentageChange ( 'college' , 'eleventhGrade' , e . target . value ) }
377388 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
378389 placeholder = "e.g., 85%"
379390 />
@@ -391,7 +402,7 @@ const EducationStep = ({ formData, onInputChange }) => {
391402 < input
392403 type = "text"
393404 value = { formData . education ?. college ?. twelfthGrade || '' }
394- onChange = { ( e ) => updateSubSection ( 'college' , 'twelfthGrade' , e . target . value ) }
405+ onChange = { ( e ) => handlePercentageChange ( 'college' , 'twelfthGrade' , e . target . value ) }
395406 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
396407 placeholder = "e.g., 90%"
397408 />
@@ -569,7 +580,7 @@ const EducationStep = ({ formData, onInputChange }) => {
569580 < input
570581 type = "text"
571582 value = { formData . education ?. graduation ?. firstYearPercentage || '' }
572- onChange = { ( e ) => updateSubSection ( 'graduation' , 'firstYearPercentage' , e . target . value ) }
583+ onChange = { ( e ) => handlePercentageChange ( 'graduation' , 'firstYearPercentage' , e . target . value ) }
573584 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
574585 placeholder = "e.g., 85%"
575586 />
@@ -587,7 +598,7 @@ const EducationStep = ({ formData, onInputChange }) => {
587598 < input
588599 type = "text"
589600 value = { formData . education ?. graduation ?. secondYearPercentage || '' }
590- onChange = { ( e ) => updateSubSection ( 'graduation' , 'secondYearPercentage' , e . target . value ) }
601+ onChange = { ( e ) => handlePercentageChange ( 'graduation' , 'secondYearPercentage' , e . target . value ) }
591602 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
592603 placeholder = "e.g., 87%"
593604 />
@@ -605,7 +616,7 @@ const EducationStep = ({ formData, onInputChange }) => {
605616 < input
606617 type = "text"
607618 value = { formData . education ?. graduation ?. thirdYearPercentage || '' }
608- onChange = { ( e ) => updateSubSection ( 'graduation' , 'thirdYearPercentage' , e . target . value ) }
619+ onChange = { ( e ) => handlePercentageChange ( 'graduation' , 'thirdYearPercentage' , e . target . value ) }
609620 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
610621 placeholder = "e.g., 89%"
611622 />
@@ -623,7 +634,7 @@ const EducationStep = ({ formData, onInputChange }) => {
623634 < input
624635 type = "text"
625636 value = { formData . education ?. graduation ?. finalYearPercentage || '' }
626- onChange = { ( e ) => updateSubSection ( 'graduation' , 'finalYearPercentage' , e . target . value ) }
637+ onChange = { ( e ) => handlePercentageChange ( 'graduation' , 'finalYearPercentage' , e . target . value ) }
627638 className = "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-[#169AB4] focus:border-transparent"
628639 placeholder = "e.g., 91%"
629640 />
0 commit comments