ConvertFieldAPIRulesToJoi.ts
2 years ago
PrepareFormData.ts
2 years ago
amountFormatter.ts
2 years ago
buildRegisterValidationOptions.ts
2 years ago
conditionOperatorFunctions.js
2 years ago
convertValuesToFormData.ts
2 years ago
createValidationObjectFromFields.js
2 years ago
generateRequestErrors.ts
2 years ago
getCurrentFormUrlData.js
2 years ago
getDefaultValuesFromSections.ts
2 years ago
getDonationFormNodeSettings.ts
2 years ago
getErrorByFieldName.ts
2 years ago
getWindowData.ts
2 years ago
groups.ts
2 years ago
handleFormRedirect.ts
2 years ago
handleFormSubmitRequest.ts
2 years ago
handleValidationRequest.ts
2 years ago
isRouteInlineRedirect.ts
2 years ago
memoNode.ts
2 years ago
mountWindowData.ts
2 years ago
postData.ts
2 years ago
postFormData.ts
2 years ago
registerFieldAndBuildProps.tsx
2 years ago
createValidationObjectFromFields.js
43 lines
| 1 | function createValidationObjectFromFields(fields) { |
| 2 | return fields.reduce((rules, field) => { |
| 3 | let rule = Joi; |
| 4 | |
| 5 | if (field.nodes) { |
| 6 | field.nodes.map(({name, type, validationRules}) => { |
| 7 | if (type === 'group') { |
| 8 | return null; |
| 9 | } |
| 10 | if (validationRules?.required) { |
| 11 | rule = rule.required(); |
| 12 | } |
| 13 | |
| 14 | if (field.type === 'email') { |
| 15 | rule = rule.email({tlds: false}); |
| 16 | } |
| 17 | |
| 18 | if (field.type === 'text') { |
| 19 | rule = rule.string(); |
| 20 | } |
| 21 | |
| 22 | rules[name] = rule; |
| 23 | }); |
| 24 | } else { |
| 25 | if (field.validationRules?.required) { |
| 26 | rule = rule.required(); |
| 27 | } |
| 28 | |
| 29 | if (field.type === 'email') { |
| 30 | rule = rule.email({tlds: false}); |
| 31 | } |
| 32 | |
| 33 | if (field.type === 'text') { |
| 34 | rule = rule.string(); |
| 35 | } |
| 36 | |
| 37 | rules[field.name] = rule; |
| 38 | } |
| 39 | |
| 40 | return rules; |
| 41 | }, {}); |
| 42 | } |
| 43 |