Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit 7cc81a8

Browse files
authored
Dynamically change the remaining number of characters required. (#88)
* Dynamically change the remaining number of characters required. * Changed text, also added string length function for removing white space * ES6 1 line fnc instead of 3 * forgot npm run fomat
1 parent 672eac8 commit 7cc81a8

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

src/views/pages/ApplicationsView/ApplicationSteps.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ function FormChallenge({
430430
}) {
431431
const classes = useStyles();
432432
const [formData, updateFormData] = useState(data.challenge);
433+
const MIN_CHAR = 150;
433434

434435
const handleChange = event => {
435436
updateFormData({
@@ -461,10 +462,11 @@ function FormChallenge({
461462
setActiveStep(3);
462463
};
463464

465+
const countChar = string => string.replace(/\s/g, '').length;
466+
464467
useEffect(() => {
465468
ValidatorForm.addValidationRule('isNotShort', value => {
466-
console.log(value);
467-
if (value.length < 100) {
469+
if (countChar(value) < MIN_CHAR) {
468470
return false;
469471
}
470472
return true;
@@ -486,7 +488,18 @@ function FormChallenge({
486488
validators={['required', 'isNotShort']}
487489
errorMessages={[
488490
'This is a required field',
489-
'Text too short. Put in atleast 150 chars.'
491+
`Text too short.
492+
${
493+
formData.q1 && formData.q1.length
494+
? 'Put in ' +
495+
(MIN_CHAR - countChar(formData.q1)) +
496+
`${
497+
countChar(formData.q1) < MIN_CHAR - 1
498+
? ' characters more'
499+
: ' character more'
500+
}`
501+
: `Put in ${MIN_CHAR} characters more`
502+
}`
490503
]}
491504
/>
492505

@@ -503,7 +516,18 @@ function FormChallenge({
503516
validators={['required', 'isNotShort']}
504517
errorMessages={[
505518
'This is a required field',
506-
'Text too short. Put in atleast 150 chars.'
519+
`Text too short.
520+
${
521+
formData.q2 && formData.q2.length
522+
? 'Put in ' +
523+
(MIN_CHAR - countChar(formData.q2)) +
524+
`${
525+
countChar(formData.q2) < MIN_CHAR - 1
526+
? ' characters more'
527+
: ' character more'
528+
}`
529+
: `Put in ${MIN_CHAR} characters more`
530+
}`
507531
]}
508532
/>
509533

@@ -520,7 +544,18 @@ function FormChallenge({
520544
validators={['required', 'isNotShort']}
521545
errorMessages={[
522546
'This is a required field',
523-
'Text too short. Put in atleast 150 chars.'
547+
`Text too short.
548+
${
549+
formData.q3 && formData.q3.length
550+
? 'Put in ' +
551+
(MIN_CHAR - countChar(formData.q3)) +
552+
`${
553+
countChar(formData.q3) < MIN_CHAR - 1
554+
? ' characters more'
555+
: ' character more'
556+
}`
557+
: `Put in ${MIN_CHAR} characters more`
558+
}`
524559
]}
525560
/>
526561

src/views/pages/CLView/ApplyNowModal.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
} from '@material-ui/core';
1313
import { makeStyles } from '@material-ui/core/styles';
1414
import CircularProgress from '@material-ui/core/CircularProgress';
15-
import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator';
15+
import {
16+
ValidatorForm,
17+
TextValidator,
18+
SelectValidator
19+
} from 'react-material-ui-form-validator';
1620
import { useSnackbar } from 'notistack';
1721
import axios from 'axios';
1822

@@ -134,7 +138,10 @@ export default function ApplyNowModal() {
134138
name="email"
135139
onChange={handleChange}
136140
validators={['required', 'isEmail']}
137-
errorMessages={['This is a required field', 'Please enter a valid email']}
141+
errorMessages={[
142+
'This is a required field',
143+
'Please enter a valid email'
144+
]}
138145
/>
139146

140147
<Grid container spacing={2} justify="space-evenly">
@@ -150,7 +157,7 @@ export default function ApplyNowModal() {
150157
errorMessages={['Please select a country code']}
151158
fullWidth
152159
>
153-
{countryCodes.map((code) => {
160+
{countryCodes.map(code => {
154161
return <MenuItem value={`+${code}`}>+{code}</MenuItem>;
155162
})}
156163
</SelectValidator>
@@ -166,8 +173,14 @@ export default function ApplyNowModal() {
166173
fullWidth
167174
name="phone"
168175
onChange={handleChange}
169-
validators={['required', 'matchRegexp:^[+]*[(]*[+]{0,1}[0-9]{1,3}[)]{0,1}[-s./0-9]*$']}
170-
errorMessages={['This is a required field', 'Please enter a valid contact number']}
176+
validators={[
177+
'required',
178+
'matchRegexp:^[+]*[(]*[+]{0,1}[0-9]{1,3}[)]{0,1}[-s./0-9]*$'
179+
]}
180+
errorMessages={[
181+
'This is a required field',
182+
'Please enter a valid contact number'
183+
]}
171184
/>
172185
</Grid>
173186
</Grid>
@@ -181,8 +194,14 @@ export default function ApplyNowModal() {
181194
fullWidth
182195
name="linkedIn"
183196
onChange={handleChange}
184-
validators={['required', 'matchRegexp:^(http(s)?://)?([w]+.)?linkedin.com/(pub|in|profile)']}
185-
errorMessages={['This is a required field', 'Please enter a valid URL']}
197+
validators={[
198+
'required',
199+
'matchRegexp:^(http(s)?://)?([w]+.)?linkedin.com/(pub|in|profile)'
200+
]}
201+
errorMessages={[
202+
'This is a required field',
203+
'Please enter a valid URL'
204+
]}
186205
/>
187206

188207
<TextValidator

0 commit comments

Comments
 (0)