Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…lfinance into feature/optimization
  • Loading branch information
Vaibhav sasulkar committed Sep 20, 2024
2 parents 8ce100f + 4f00d1d commit c4c848c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 509 deletions.
8 changes: 8 additions & 0 deletions blocks/form/base-64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const toBase64 = file => new Promise(async (resolve, reject) => {
const reader = new FileReader();
await reader.readAsDataURL(file);
reader.onload = () => {
resolve(reader.result);
}
reader.onerror = reject;
});
5 changes: 5 additions & 0 deletions blocks/form/form-fields.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { toClassName } from '../../scripts/aem.js';
import { toBase64 } from './base-64.js';

function createFieldWrapper(fd) {
const fieldWrapper = document.createElement('div');
Expand Down Expand Up @@ -157,6 +158,10 @@ const createInput = (fd) => {
fieldWrapper.prepend(label);
}

field.addEventListener('change', async function (e) {
const base64 = await toBase64(this.files[0])
this.dataset.fileData = base64;
})
return { field, fieldWrapper };
};

Expand Down
3 changes: 3 additions & 0 deletions blocks/form/form.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toBase64 } from './base-64.js';
import createField from './form-fields.js';

async function createForm(formHref, submitHref) {
Expand Down Expand Up @@ -33,6 +34,8 @@ function generatePayload(form) {
if (field.name && field.type !== 'submit' && !field.disabled) {
if (field.type === 'radio') {
if (field.checked) payload[field.name] = field.value;
} else if (field.type === 'file') {
payload[field.name] = field.dataset.fileData;
} else if (field.type === 'checkbox') {
if (field.checked) payload[field.name] = payload[field.name] ? `${payload[field.name]},${field.value}` : field.value;
} else {
Expand Down
4 changes: 4 additions & 0 deletions component-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,10 @@
{
"name": "used-car-loan-branch-carousel",
"value": "used-car-loan-branch-carousel"
},
{
"name": "video-component-carousel",
"value": "video-component-carousel"
}
]
},
Expand Down
237 changes: 0 additions & 237 deletions form/form-fields.js

This file was deleted.

Loading

0 comments on commit c4c848c

Please sign in to comment.