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
1 year ago
getCurrentFormUrlData.js
1 year 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
1 year ago
handleFormSubmitRequest.ts
1 year ago
handleValidationRequest.ts
2 years ago
isRouteInlineRedirect.ts
2 years ago
memoNode.ts
2 years ago
mountWindowData.ts
1 year ago
postData.ts
2 years ago
postFormData.ts
2 years ago
registerFieldAndBuildProps.tsx
1 year ago
setDesignSettings.ts
2 years ago
useDonationFormPubSub.ts
1 year ago
PrepareFormData.ts
37 lines
| 1 | import {Form, Group, isGroup, Node} from '@givewp/forms/types'; |
| 2 | import {mapGroup, reduceGroup, walkGroup} from './groups'; |
| 3 | |
| 4 | /** |
| 5 | * Receives the form data as provided directly from the server and mutates it to be ready for use by the React application |
| 6 | * |
| 7 | * @since 3.0.0 |
| 8 | */ |
| 9 | export default function prepareFormData(form: Form) { |
| 10 | form.walkNodes = walkGroupNodes.bind(form); |
| 11 | form.mapNodes = mapGroupNodes.bind(form); |
| 12 | form.reduceNodes = reduceGroupNodes.bind(form); |
| 13 | |
| 14 | form.walkNodes((node: Group) => { |
| 15 | node.walkNodes = walkGroupNodes.bind(node); |
| 16 | node.mapNodes = mapGroupNodes.bind(node); |
| 17 | node.reduceNodes = reduceGroupNodes.bind(node); |
| 18 | }, isGroup); |
| 19 | } |
| 20 | |
| 21 | function walkGroupNodes(this: Group, callback: (node: Node) => void, filter?: (node: Node) => boolean) { |
| 22 | walkGroup(this, callback, filter); |
| 23 | } |
| 24 | |
| 25 | function mapGroupNodes(this: Group, callback: (node: Node) => void, filter?: (node: Node) => boolean) { |
| 26 | return mapGroup(this, callback, filter); |
| 27 | } |
| 28 | |
| 29 | function reduceGroupNodes( |
| 30 | this: Group, |
| 31 | callback: (accumulator: any, node: Node) => any, |
| 32 | initialValue: any, |
| 33 | filter?: (node: Node) => boolean |
| 34 | ) { |
| 35 | return reduceGroup(this, callback, initialValue, filter); |
| 36 | } |
| 37 |