Sha256: 459bb2fcac7a58853f533d36a227e2583fd774153bd75c1c866ef654294dade8

Contents?: true

Size: 569 Bytes

Versions: 13

Compression:

Stored size: 569 Bytes

Contents

// Turns an Object into FormData. Note that a nested array will come out as a hash with numeric keys
// and will need to be handled accordingly server-side.
export function buildFormData(formData, data, parentKey) {
  if (data && typeof data === 'object' && !(data instanceof Date) && !(data instanceof File) && !(data instanceof Blob)) {
    Object.keys(data).forEach(key => {
      buildFormData(formData, data[key], parentKey ? `${parentKey}[${key}]` : key);
    });
  } else {
    const value = data == null ? '' : data;
    formData.append(parentKey, value);
  }
}

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
coprl-3.0.0.beta.12 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.11 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.10 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.9 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.8 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.7 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.6 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.5 views/mdc/assets/js/utils/form-data.js
voom-presenters-2.1.2 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.4 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.3 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.2 views/mdc/assets/js/utils/form-data.js
coprl-3.0.0.beta.1 views/mdc/assets/js/utils/form-data.js