Skip to content

Commit

Permalink
Fix field types for number and time fields.
Browse files Browse the repository at this point in the history
Fix values passing to checkbox wrapper.
  • Loading branch information
robgietema committed Jan 15, 2025
1 parent 4944c2d commit b5fd610
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { toast } from 'react-toastify';
import { Toast } from '@plone/volto/components';
import { useLocation } from 'react-router-dom';
import qs from 'query-string';
import { includes, keys, map, pickBy, without } from 'lodash';
import { includes, keys, map, pickBy, without, isObject } from 'lodash';
import { Grid, Message } from 'semantic-ui-react';
import config from '@plone/volto/registry';
import { renderToString } from 'react-dom/server';
Expand Down Expand Up @@ -77,6 +77,23 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => {
),
);

map(keys(submitData), (field) => {
if (
data.schema.properties[field].factory === 'number' &&
submitData[field] !== undefined
) {
submitData[field] = parseInt(submitData[field]);
}

if (
data.schema.properties[field].factory === 'time' &&
isObject(submitData[field])
) {
submitData[field] =
`${submitData[field].hour}:${submitData[field].minute}`;
}
});

dispatch(submitForm(path, id, submitData, captcha))
.then((resp) => {
setSubmitted(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ const CheckboxWrapper = (props) => {
value={value || ''}
label={title}
description={description}
default={props.default}
isRequired={required}
labelRequired={intl.formatMessage(messages.required)}
disabled={isDisabled}
onChange={(value) => onChange(id, value === '' ? undefined : value)}
ref={ref}
onClick={() => onClick()}
errorMessage={error ? error[0] : ''}
isInvalid={error}
isInvalid={error !== undefined}
/>
</FormFieldWrapper>
);
Expand Down

0 comments on commit b5fd610

Please sign in to comment.