Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widgets: propagate initial value field #253

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/lib/forms/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class TextField extends Component {
label,
optimized,
required,
value,
...uiProps
} = this.props;
const FormikField = optimized ? FastField : Field;
Expand All @@ -30,6 +31,7 @@ export class TextField extends Component {
className="invenio-text-input-field"
id={fieldPath}
name={fieldPath}
value={value}
>
{({ field, meta }) => {
return (
Expand All @@ -39,14 +41,15 @@ export class TextField extends Component {
error ||
meta.error ||
// We check if initialValue changed to display the initialError,
// otherwise it would be displayed despite updating the fieldu
// otherwise it would be displayed despite updating the field
(!meta.touched && meta.initialError)
}
disabled={disabled}
fluid
label={label}
id={fieldPath}
required={required}
value={value}
{...uiProps}
/>
);
Expand All @@ -66,6 +69,7 @@ TextField.propTypes = {
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
optimized: PropTypes.bool,
required: PropTypes.bool,
value: PropTypes.string,
};

TextField.defaultProps = {
Expand All @@ -74,4 +78,5 @@ TextField.defaultProps = {
disabled: false,
optimized: false,
required: false,
value: undefined,
};
5 changes: 4 additions & 1 deletion src/lib/forms/widgets/select/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Dropdown extends Component {
multiple,
clearable,
required,
defaultValue,
} = this.props;
return (
<>
Expand All @@ -41,7 +42,7 @@ export default class Dropdown extends Component {
clearable={clearable}
required={required}
optimized
defaultValue={multiple ? [] : ""}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to dropdowns with multiple values if you don't pass anything when e.g save a record? Does the component complain? I guess if we don't initialize the defaultValue to the proper initial value there might be that SUI complains... Can you test also the above behaviour with the RemoteSelectField?

defaultValue={defaultValue}
/>
{description && <label className="helptext">{description}</label>}
</>
Expand All @@ -65,6 +66,7 @@ Dropdown.propTypes = {
multiple: PropTypes.bool,
clearable: PropTypes.bool,
required: PropTypes.bool,
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
};

Dropdown.defaultProps = {
Expand All @@ -73,4 +75,5 @@ Dropdown.defaultProps = {
multiple: false,
clearable: true,
required: false,
defaultValue: undefined,
};
4 changes: 4 additions & 0 deletions src/lib/forms/widgets/text/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Input extends Component {
description,
disabled,
type,
value,
} = this.props;

return (
Expand All @@ -27,6 +28,7 @@ export default class Input extends Component {
label={<FieldLabel htmlFor={fieldPath} icon={icon} label={label} />}
placeholder={placeholder}
type={type}
value={value}
/>
);
}
Expand All @@ -41,11 +43,13 @@ Input.propTypes = {
required: PropTypes.bool,
disabled: PropTypes.bool,
type: PropTypes.string,
value: PropTypes.any,
};

Input.defaultProps = {
icon: undefined,
required: false,
disabled: false,
type: "input",
value: undefined,
};
Loading