Skip to content

Commit

Permalink
fix: List - Initial value is required.
Browse files Browse the repository at this point in the history
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
  • Loading branch information
Krishna2323 committed Aug 22, 2024
1 parent f12c1ff commit f86116f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 2 additions & 7 deletions src/pages/workspace/reportFields/CreateReportFieldsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CreateReportFieldsPage({

const validateForm = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM> => {
const {name, type, initialValue} = values;
const {name, type} = values;
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM> = {};

if (!ValidationUtils.isRequiredFulfilled(name)) {
Expand All @@ -81,13 +81,9 @@ function CreateReportFieldsPage({
errors[INPUT_IDS.TYPE] = translate('workspace.reportFields.reportFieldTypeRequiredError');
}

if (type === CONST.REPORT_FIELD_TYPES.LIST && availableListValuesLength > 0 && !ValidationUtils.isRequiredFulfilled(initialValue)) {
errors[INPUT_IDS.INITIAL_VALUE] = translate('workspace.reportFields.reportFieldInitialValueRequiredError');
}

return errors;
},
[availableListValuesLength, policy?.fieldList, translate],
[policy?.fieldList, translate],
);

useEffect(() => {
Expand Down Expand Up @@ -186,7 +182,6 @@ function CreateReportFieldsPage({
inputID={INPUT_IDS.INITIAL_VALUE}
label={translate('common.initialValue')}
subtitle={translate('workspace.reportFields.listValuesInputSubtitle')}
rightLabel={translate('common.required')}
/>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function ReportFieldsInitialValuePage({

const submitForm = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM>) => {
ReportField.updateReportFieldInitialValue(policyID, reportFieldID, values.initialValue);
ReportField.updateReportFieldInitialValue(policyID, reportFieldID, initialValue === values.initialValue ? '' : values.initialValue);
Navigation.goBack();
},
[policyID, reportFieldID],
[policyID, reportFieldID, initialValue],
);

const submitListValueUpdate = (value: string) => {
ReportField.updateReportFieldInitialValue(policyID, reportFieldID, value);
ReportField.updateReportFieldInitialValue(policyID, reportFieldID, initialValue === value ? '' : value);
Navigation.goBack();
};

Expand Down

0 comments on commit f86116f

Please sign in to comment.