(checkUser, setminRequiredCount)
| 4409 | |
| 4410 | //function is used to check required and optional widgets and ensure required widget should be response |
| 4411 | export const handleCheckResponse = (checkUser, setminRequiredCount) => { |
| 4412 | let checkboxExist, |
| 4413 | showAlert = false, |
| 4414 | widgetKey, |
| 4415 | requiredCheckbox, |
| 4416 | tourPageNumber; // `pageNumber` is used to check on which page user did not fill widget's data then change current pageNumber and show tour message on that page |
| 4417 | for (let i = 0; i < checkUser[0].placeHolder.length; i++) { |
| 4418 | for (let j = 0; j < checkUser[0].placeHolder[i].pos.length; j++) { |
| 4419 | //get current page |
| 4420 | const updatePage = checkUser[0].placeHolder[i]?.pageNumber; |
| 4421 | //checking checbox type widget |
| 4422 | checkboxExist = checkUser[0].placeHolder[i].pos[j].type === "checkbox"; |
| 4423 | //condition to check checkbox widget exist or not |
| 4424 | if (checkboxExist) { |
| 4425 | //get all required type checkbox |
| 4426 | requiredCheckbox = checkUser[0].placeHolder[i].pos.filter( |
| 4427 | (position) => { |
| 4428 | return ( |
| 4429 | !position.options?.isReadOnly && position.type === "checkbox" |
| 4430 | ); |
| 4431 | } |
| 4432 | ); |
| 4433 | //if required type checkbox data exit then check user checked all checkbox or some checkbox remain to check |
| 4434 | //also validate to minimum and maximum required checkbox |
| 4435 | if (requiredCheckbox && requiredCheckbox.length > 0) { |
| 4436 | for (let i = 0; i < requiredCheckbox.length; i++) { |
| 4437 | //get minimum required count if exit |
| 4438 | const minCount = |
| 4439 | requiredCheckbox[i].options?.validation?.minRequiredCount; |
| 4440 | const parseMin = minCount && parseInt(minCount); |
| 4441 | //get maximum required count if exit |
| 4442 | const maxCount = |
| 4443 | requiredCheckbox[i].options?.validation?.maxRequiredCount; |
| 4444 | const parseMax = maxCount && parseInt(maxCount); |
| 4445 | //in `response` variable is used to get how many checkbox checked by user |
| 4446 | const response = requiredCheckbox[i].options?.response?.length; |
| 4447 | //in `defaultValue` variable is used to get how many checkbox checked by default |
| 4448 | const defaultValue = |
| 4449 | requiredCheckbox[i].options?.defaultValue?.length; |
| 4450 | const checkboxValue = response ? response : defaultValue; |
| 4451 | //condition to check parseMin and parseMax greater than 0 then consider it as a required check box |
| 4452 | if ( |
| 4453 | parseMin > 0 && |
| 4454 | parseMax > 0 && |
| 4455 | !response && |
| 4456 | !defaultValue && |
| 4457 | !showAlert |
| 4458 | ) { |
| 4459 | showAlert = true; |
| 4460 | widgetKey = requiredCheckbox[i].key; |
| 4461 | tourPageNumber = updatePage; |
| 4462 | setminRequiredCount(parseMin); |
| 4463 | } |
| 4464 | //else condition to validate minimum required checkbox |
| 4465 | else if ( |
| 4466 | parseMin > 0 && |
| 4467 | (parseMin > checkboxValue || !checkboxValue) |
| 4468 | ) { |
no test coverage detected