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
getDefaultValuesFromSections.ts
27 lines
| 1 | /** |
| 2 | * Returns default values from an array of field collection objects |
| 3 | * |
| 4 | * @since 3.0.0 |
| 5 | * |
| 6 | * @param sections |
| 7 | * @return {*} |
| 8 | */ |
| 9 | import {Section} from '@givewp/forms/types'; |
| 10 | import {reduceFields} from './groups'; |
| 11 | |
| 12 | export default function getDefaultValuesFromSections(sections: Section[]) { |
| 13 | return reduceFields( |
| 14 | sections, |
| 15 | (values, field) => { |
| 16 | const defaultValue = field.defaultValue; |
| 17 | |
| 18 | if (defaultValue !== null && defaultValue !== '') { |
| 19 | values[field.name] = defaultValue; |
| 20 | } |
| 21 | |
| 22 | return values; |
| 23 | }, |
| 24 | {} |
| 25 | ); |
| 26 | } |
| 27 |