Skip to content

Commit

Permalink
removed hasError boolean from form elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ridz1208 committed Nov 6, 2024
1 parent 38266d4 commit bbe01bf
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 135 deletions.
7 changes: 2 additions & 5 deletions jsx/Form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ type selectElementProps = {
required?: boolean
emptyOption?: boolean
autoSelect?: boolean
hasError?: boolean
errorMessage?: boolean
errorMessage?: string
onUserInput: (name: string, value: any) => void
noMargins?: boolean
placeholder?: string
Expand Down Expand Up @@ -306,7 +305,6 @@ type fileElementProps = {
disabled?: boolean
required?: boolean
allowMultiple?: boolean
hasError?: boolean
errorMessage?: string
onUserInput: (name: string, value: any) => void
};
Expand Down Expand Up @@ -407,7 +405,6 @@ type dateElementProps = {
dateFormat?: string
disabled?: boolean
required?: boolean
hasError?: boolean
errorMessage?: string
onUserInput: (name: string, value: any) => void
};
Expand Down Expand Up @@ -595,7 +592,7 @@ type radioElementProps = {
required?: boolean
vertical?: boolean
checked: boolean
errorMessage?: boolean
errorMessage?: string
elementClass?: boolean
onUserInput: (name: string, value: any) => void
}
Expand Down
35 changes: 14 additions & 21 deletions jsx/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ SearchableDropdown.defaultProps = {
disabled: false,
required: false,
sortByValue: true,
errorMessage: '',
errorMessage: null,
placeHolder: '',
onUserInput: function() {
console.warn('onUserInput() callback is not set');
Expand Down Expand Up @@ -554,7 +554,7 @@ export class SelectElement extends Component {
}

// Add error message
if (this.props.hasError
if (this.props.errorMessage
|| (this.props.required && this.props.value === '')
) {
errorMessage = <span>{this.props.errorMessage}</span>;
Expand Down Expand Up @@ -660,7 +660,6 @@ SelectElement.propTypes = {
required: PropTypes.bool,
emptyOption: PropTypes.bool,
autoSelect: PropTypes.bool,
hasError: PropTypes.bool,
errorMessage: PropTypes.string,
onUserInput: PropTypes.func,
noMargins: PropTypes.bool,
Expand All @@ -680,8 +679,7 @@ SelectElement.defaultProps = {
sortByValue: true,
emptyOption: true,
autoSelect: true,
hasError: false,
errorMessage: 'The field is required!',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -978,11 +976,10 @@ TagsElement.defaultProps = {
required: false,
disabled: false,
emptyOption: true,
hasError: false,
allowDupl: false,
useSearch: false,
strictSearch: false, // only accept items specified in options
errorMessage: '',
errorMessage: null,
pendingValKey: '',
btnLabel: 'Add Tag',
onUserInput: function() {
Expand Down Expand Up @@ -1213,7 +1210,7 @@ TextboxElement.defaultProps = {
autoComplete: null,
disabled: false,
required: false,
errorMessage: '',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -1345,7 +1342,7 @@ EmailElement.defaultProps = {
autoComplete: null,
disabled: false,
required: false,
errorMessage: '',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -1506,7 +1503,7 @@ PasswordElement.defaultProps = {
disabled: false,
required: false,
autoComplete: null,
errorMessage: '',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -1560,7 +1557,7 @@ export class DateElement extends Component {
}

// Add error message
if (this.props.hasError
if (this.props.errorMessage
|| (this.props.required && this.props.value === '')
) {
errorMessage = <span>{this.props.errorMessage}</span>;
Expand Down Expand Up @@ -1640,7 +1637,6 @@ DateElement.propTypes = {
dateFormat: PropTypes.string,
disabled: PropTypes.bool,
required: PropTypes.bool,
hasError: PropTypes.bool,
errorMessage: PropTypes.string,
onUserInput: PropTypes.func,
};
Expand All @@ -1655,8 +1651,7 @@ DateElement.defaultProps = {
dateFormat: 'YMd',
disabled: false,
required: false,
hasError: false,
errorMessage: 'The field is required!',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -2039,7 +2034,7 @@ export class FileElement extends Component {
};

// Add error message
if (this.props.hasError) {
if (this.props.errorMessage) {
errorMessage = this.props.errorMessage;
elementClass = 'row form-group has-error';
}
Expand Down Expand Up @@ -2125,7 +2120,6 @@ FileElement.propTypes = {
disabled: PropTypes.bool,
required: PropTypes.bool,
allowMultiple: PropTypes.bool,
hasError: PropTypes.bool,
errorMessage: PropTypes.string,
onUserInput: PropTypes.func,
};
Expand All @@ -2138,8 +2132,7 @@ FileElement.defaultProps = {
disabled: false,
required: false,
allowMultiple: false,
hasError: false,
errorMessage: 'The field is required!',
errorMessage: null,
onUserInput: function() {
console.warn('onUserInput() callback is not set');
},
Expand Down Expand Up @@ -2396,7 +2389,7 @@ CheckboxElement.defaultProps = {
id: null,
disabled: false,
required: false,
errorMessage: '',
errorMessage: null,
offset: 'col-sm-offset-3',
class: 'checkbox-inline',
elementClass: 'checkbox-inline col-sm-offset-3',
Expand Down Expand Up @@ -2760,7 +2753,7 @@ RadioElement.defaultProps = {
disabled: false,
required: false,
vertical: false,
errorMessage: '',
errorMessage: null,
elementClass: 'row form-group',
onUserInput: function() {
console.warn('onUserInput() callback is not set');
Expand Down Expand Up @@ -2905,7 +2898,7 @@ SliderElement.defaultProps = {
maxWidth: 'auto',
disabled: false,
required: false,
errorMessage: '',
errorMessage: null,
elementClass: 'row form-group',
onUserInput: function() {
console.warn('onUserInput() callback is not set');
Expand Down
3 changes: 1 addition & 2 deletions jsx/form/DateTimePartialElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ interface DateTimePartialElementProps {
dateFormat: string;
required?: boolean;
disabled?: boolean;
hasError?: boolean;
errorMessage?: string;
onUserInput: (name: string, value: string) => void;
}
Expand Down Expand Up @@ -185,7 +184,7 @@ function DateTimePartialElement(props: DateTimePartialElementProps) {
if (props.required && value == '') {
errorMessage = <span>This field is required</span>;
elementClass += ' has-error';
} else if (props.hasError) {
} else if (props.errorMessage) {
errorMessage = <span>{props.errorMessage}</span>;
elementClass += ' has-error';
}
Expand Down
4 changes: 0 additions & 4 deletions modules/battery_manager/jsx/batteryManagerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class BatteryManagerForm extends Component {
required={true}
value={test.testName}
errorMessage={errors.testName}
hasError={errors.testName}
/>
<NumericElement
name="ageMinDays"
Expand All @@ -79,7 +78,6 @@ class BatteryManagerForm extends Component {
required={true}
value={test.ageMinDays}
errorMessage={errors.ageMinDays}
hasError={errors.ageMinDays}
/>
<NumericElement
name="ageMaxDays"
Expand All @@ -90,7 +88,6 @@ class BatteryManagerForm extends Component {
required={true}
value={test.ageMaxDays}
errorMessage={errors.ageMaxDays}
hasError={errors.ageMaxDays}
/>
<SelectElement
name="stage"
Expand All @@ -100,7 +97,6 @@ class BatteryManagerForm extends Component {
required={true}
value={test.stage}
errorMessage={errors.stage}
hasError={errors.stage}
/>
<SelectElement
name="cohort"
Expand Down
9 changes: 4 additions & 5 deletions modules/conflict_resolver/jsx/fix_conflict_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FixConflictForm extends Component {
this.state = {
value: null,
success: false,
error: false,
error: null,
emptyOption: true,
};

Expand Down Expand Up @@ -68,11 +68,11 @@ class FixConflictForm extends Component {
if (json.error) {
throw json.error;
}
this.setState({success: true, error: false, emptyOption: false, value});
this.setState({success: true, error: null, emptyOption: false, value});
})
.catch((error) => {
swal('Error!', error, 'error');
this.setState({error: true, success: false, emptyOption: true});
this.setState({error, success: false, emptyOption: true});
});
}

Expand All @@ -95,8 +95,7 @@ class FixConflictForm extends Component {
onUserInput={this.resolveConflict}
options={this.props.options}
emptyOption={emptyOption}
hasError={error}
errorMessage={''}
errorMessage={error}
noMargins={true}
/>
</td>
Expand Down
15 changes: 1 addition & 14 deletions modules/data_release/jsx/addPermissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AddPermissionForm extends Component {
data: {},
fieldOptions: {},
formData: {},
hasError: {},
errorMessage: {},
isLoaded: false,
loadedData: 0,
Expand Down Expand Up @@ -95,7 +94,6 @@ class AddPermissionForm extends Component {
options={this.state.fieldOptions.users}
onUserInput={this.setFormData}
ref='userid'
hasError={this.state.hasError.Username}
errorMessage={this.state.errorMessage.Username}
required={true}
value={this.state.formData.userid}
Expand All @@ -107,7 +105,6 @@ class AddPermissionForm extends Component {
options={this.state.fieldOptions.filenames}
onUserInput={this.setFormData}
ref='data_release_id'
hasError={this.state.hasError.Filename}
errorMessage={this.state.errorMessage.Filename}
required={false}
value={this.state.formData.data_release_id}
Expand All @@ -120,7 +117,6 @@ class AddPermissionForm extends Component {
options={this.state.fieldOptions.versions}
onUserInput={this.setFormData}
ref='data_release_version'
hasError={this.state.hasError.Version}
errorMessage={this.state.errorMessage.Version}
required={false}
value={this.state.formData.data_release_version}
Expand Down Expand Up @@ -208,16 +204,9 @@ class AddPermissionForm extends Component {
Version: undefined,
};

let hasError = {
Username: false,
Filename: false,
Version: false,
};

// make sure a user was selected
if (!formData.userid) {
errorMessage.Username = 'You must select a user!';
hasError.Username = true;
isValid = false;
}

Expand All @@ -227,12 +216,10 @@ class AddPermissionForm extends Component {
let msg = 'You must select a file OR a version to grant permission on!';
errorMessage.Filename = msg;
errorMessage.Version = msg;
hasError.Filename = true;
hasError.Version = true;
isValid = false;
}

this.setState({errorMessage, hasError});
this.setState({errorMessage});
return isValid;
}
}
Expand Down
1 change: 0 additions & 1 deletion modules/data_release/jsx/managePermissionsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ManagePermissionsForm extends Component {
this.state = {
data: {},
originalData: {},
hasError: {},
errorMessage: {},
isLoaded: false,
};
Expand Down
15 changes: 3 additions & 12 deletions modules/data_release/jsx/uploadFileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class UploadFileForm extends Component {
formData: {},
uploadResult: null,
errorMessage: {},
hasError: {},
isLoaded: false,
uploadProgress: -1,
};
Expand Down Expand Up @@ -127,22 +126,15 @@ class UploadFileForm extends Component {
Filesize: undefined,
};

let hasError = {
Filename: undefined,
Filesize: undefined,
};

if (!formData.file) {
errorMessage.Filename = 'You must select a file to upload';
hasError.Filename = true;
this.setState({errorMessage, hasError});
this.setState({errorMessage});
return;
}

if (!formData.project) {
errorMessage.Project = 'You must select a project';
hasError.Project = true;
this.setState({errorMessage, hasError});
this.setState({errorMessage});
return;
}

Expand All @@ -154,14 +146,13 @@ class UploadFileForm extends Component {
+ maxSizeAllowed
+ ')';
errorMessage['Filesize'] = msg;
hasError['Filesize'] = true;
swal.fire({
title: 'Error',
text: msg,
type: 'error',
showCancelButton: true,
});
this.setState({errorMessage, hasError});
this.setState({errorMessage});
return;
}

Expand Down
Loading

0 comments on commit bbe01bf

Please sign in to comment.