Skip to content

Commit

Permalink
files should be required - fixing cancel button behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Jan 17, 2025
1 parent a17781a commit 71eb4d1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/form/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Field extends React.Component {
const { properties, onChange, formContext } = this.props;

const defaultOnChange = (value) => {
if (typeof value === "object" && Object.prototype.hasOwnProperty.call(value, 'checked')) {
if (typeof value === "object" && value !== null && Object.prototype.hasOwnProperty.call(value, 'checked')) {
formContext.setFormValues({ [properties.name]: value.checked });
} else {
formContext.setFormValues({ [properties.name]: value });
Expand Down
4 changes: 2 additions & 2 deletions components/form/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class File extends FormElement {
triggerCancel() {
this.setState({
accepted: [],
value: null
value: ''
}, () => {
// Publish the new value to the form
if (this.props.onChange) this.props.onChange(this.state.value);
Expand Down Expand Up @@ -159,7 +159,7 @@ class File extends FormElement {
<input
{...omit(properties, 'authorization')}
className={`input ${inputClassName}`}
value={this.state.value?.name}
value={this.state.value?.name || ''}
placeholder={this.props.intl.formatMessage({ id: 'select-file' })}
readOnly={!changeableName}
id={`input-${properties.name}`}
Expand Down
4 changes: 2 additions & 2 deletions components/ui/country-doc-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ class DocModal extends React.Component {
<div className="l-row row">
<div className="columns small-12">
<Field
validations={!url ? ['required'] : []}
validations={['required']}
className="-fluid"
properties={{
name: 'file',
label: intl.formatMessage({ id: 'file' }),
required: !url,
required: true,
default: !url ? null : { name: url }
}}
>
Expand Down
4 changes: 2 additions & 2 deletions components/ui/doc-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ class DocModal extends React.Component {
<div className="l-row row">
<div className="columns small-12">
<Field
validations={!url ? ['required'] : []}
validations={['required']}
className="-fluid"
properties={{
name: 'file',
label: intl.formatMessage({ id: 'file' }),
required: !url,
required: true,
default: !url ? null : { name: url }
}}
>
Expand Down

0 comments on commit 71eb4d1

Please sign in to comment.