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

Fix file cancel button, and validations #230

Merged
merged 1 commit into from
Jan 17, 2025
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
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
Loading