fix(client):format url values on form submit

This commit is contained in:
Valeriy
2019-06-17 23:40:47 +03:00
committed by mrugesh
parent c99366fa71
commit fbb8311af7
3 changed files with 38 additions and 38 deletions

View File

@@ -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

View File

@@ -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) {