fix(client):format url values on form submit
This commit is contained in:
@@ -2,7 +2,12 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { reduxForm } from 'redux-form';
|
||||
|
||||
import { FormFields, BlockSaveButton, BlockSaveWrapper } from './';
|
||||
import {
|
||||
FormFields,
|
||||
BlockSaveButton,
|
||||
BlockSaveWrapper,
|
||||
formatUrlValues
|
||||
} from './';
|
||||
|
||||
const propTypes = {
|
||||
buttonText: PropTypes.string,
|
||||
@@ -48,7 +53,9 @@ export function DynamicForm({
|
||||
return (
|
||||
<form
|
||||
id={`dynamic-${id}`}
|
||||
onSubmit={handleSubmit(submit)}
|
||||
onSubmit={handleSubmit((values, ...args) =>
|
||||
submit(formatUrlValues(values, options), ...args)
|
||||
)}
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
<FormFields
|
||||
|
@@ -15,6 +15,16 @@ export function callIfDefined(fn) {
|
||||
return value => (value ? fn(value) : value);
|
||||
}
|
||||
|
||||
export function formatUrlValues(values, options) {
|
||||
return Object.keys(values).reduce((result, key) => {
|
||||
let value = values[key];
|
||||
if (options.types[key] === 'url') {
|
||||
value = normalizeUrl(value, normalizeOptions);
|
||||
}
|
||||
return { ...result, [key]: value };
|
||||
}, {});
|
||||
}
|
||||
|
||||
// formatUrl(url: String) => String
|
||||
export function formatUrl(url) {
|
||||
if (typeof url === 'string' && url.length > 4 && url.indexOf('.') !== -1) {
|
||||
|
Reference in New Issue
Block a user