Skip to content

Commit

Permalink
Fix file widget in thank you page.
Browse files Browse the repository at this point in the history
Fix select widget default value.
  • Loading branch information
robgietema committed Dec 14, 2024
1 parent 71754f9 commit 510268e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,24 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => {

const formfields = renderToString(
<Grid stackable columns={2}>
{map(keys(submittedData), (property) => (
<Grid.Row>
<Grid.Column>{data.schema.properties[property].title}</Grid.Column>
<Grid.Column>{submittedData[property]}</Grid.Column>
</Grid.Row>
))}
{map(keys(submittedData), (property) => {
const propertyType = data.schema.properties[property].type;

// Only render if the type is not 'object'
if (propertyType !== 'object') {
return (
<Grid.Row key={property}>
<Grid.Column>
{data.schema.properties[property].title}
</Grid.Column>
<Grid.Column>{submittedData[property]}</Grid.Column>
</Grid.Row>
);
}

// Return null to avoid rendering the row for object types
return null;
})}
</Grid>,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useRef } from 'react';
import PropTypes from 'prop-types';
import config from '@plone/volto/registry';
import { defineMessages, injectIntl } from 'react-intl';
import { isString, map } from 'lodash';

import FormFieldWrapper from './FormFieldWrapper';

Expand Down Expand Up @@ -35,13 +36,25 @@ const CheckboxGroupWrapper = (props) => {

const options = choices || [];

const curValue = value
? isString(value)
? value.split('\n')
: value
: undefined;

const curDefault = props.default
? isString(props.default)
? props.default.split('\n')
: props.default
: undefined;

return (
<FormFieldWrapper {...props} className="text">
{options.length < 6 && (
<CheckboxGroup
id={`field-${id}`}
name={id}
value={value || []}
value={curValue || []}
label={title}
description={description}
isRequired={required}
Expand All @@ -61,8 +74,13 @@ const CheckboxGroupWrapper = (props) => {
id={`field-${id}`}
name={id}
value={
(value && { value, label: value }) ||
(props.default && { value: props.default, label: props.default }) ||
(curValue &&
map(curValue, (item) => ({ value: item, label: item }))) ||
(curDefault &&
map(curDefault, (item) => ({
value: item,
label: item,
}))) ||
undefined
}
label={title}
Expand All @@ -71,7 +89,12 @@ const CheckboxGroupWrapper = (props) => {
isMulti={true}
labelRequired={intl.formatMessage(messages.required)}
disabled={isDisabled}
onChange={(value) => onChange(id, value.value)}
onChange={(value) => {
return onChange(
id,
map(value, (item) => item.value),
);
}}
ref={ref}
onClick={() => onClick()}
options={options.map((option) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const DatetimeWrapper = (props) => {
name={id}
value={value || null}
label={title}
locale={intl.locale}
description={description}
isRequired={required}
labelRequired={intl.formatMessage(messages.required)}
Expand Down

0 comments on commit 510268e

Please sign in to comment.