Skip to content

Commit

Permalink
Bug/WP-792: disable submit if form is not modified. (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc authored Dec 4, 2024
1 parent 85903f1 commit 23f7667
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const EditExceptionModal: React.FC<EditRecordModalProps> = ({
<Button
type="primary"
attr="submit"
disabled={formik.isSubmitting}
disabled={!formik.dirty || formik.isSubmitting}
>
Submit
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Modal,
ModalBody,
ModalHeader,
Button,
Label,
FormGroup,
Row,
Expand All @@ -15,6 +14,7 @@ import * as Yup from 'yup';
import { UserRow } from 'hooks/admin';
import styles from './ViewUsers.module.scss';
import { formatDate } from 'utils/dateUtil';
import Button from 'core-components/Button';

interface EditRecordModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -123,7 +123,7 @@ const EditRecordModal: React.FC<EditRecordModalProps> = ({
validationSchema={validationSchema}
onSubmit={handleSave}
>
{({ isSubmitting }) => (
{({ isSubmitting, dirty }) => (
<Form>
<Row>
<Col md={3}>
Expand Down Expand Up @@ -236,10 +236,9 @@ const EditRecordModal: React.FC<EditRecordModalProps> = ({
</Row>
<br />
<Button
type="submit"
color="primary"
disabled={isSubmitting}
className={styles.customSubmitButton}
type="primary"
attr="submit"
disabled={isSubmitting || !dirty}
>
Submit
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const RegistrationForm: React.FC<{
validationSchema={validationSchema}
onSubmit={handleSubmit}
>
{({ values, setFieldValue, resetForm }) => (
{({ values, setFieldValue, resetForm, dirty }) => (
useEffect(() => {
if (isSuccess) {
resetForm();
Expand Down Expand Up @@ -499,7 +499,7 @@ export const RegistrationForm: React.FC<{
type="submit"
color="primary"
className="form-button"
disabled={registrationSubmissionPending}
disabled={registrationSubmissionPending || !dirty}
>
Submit
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const ExceptionFormPage: React.FC = () => {
isValid,
submitCount,
handleSubmit,
dirty,
}) => {
// To reset values to initial values if the form submits successfully
useEffect(() => {
Expand Down Expand Up @@ -420,6 +421,7 @@ export const ExceptionFormPage: React.FC = () => {
<Button
type="primary"
attr="submit"
disabled={isSubmitting || !dirty}
isLoading={isSubmitting}
onClick={() => setIsSuccess(false)}
>
Expand All @@ -439,6 +441,7 @@ export const ExceptionFormPage: React.FC = () => {
<Button
type="primary"
attr="submit"
disabled={isSubmitting || !dirty}
isLoading={isSubmitting}
onClick={() => setIsSuccess(false)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const ExtensionRequestForm: React.FC = () => {
validationSchema={validationSchema}
onSubmit={handleSubmit}
>
{({ values, isSubmitting, setFieldValue, resetForm }) => {
{({ values, isSubmitting, setFieldValue, resetForm, dirty }) => {
useEffect(() => {
if (isSuccess) {
resetForm();
Expand Down Expand Up @@ -269,6 +269,7 @@ export const ExtensionRequestForm: React.FC = () => {
<Button
type="primary"
attr="submit"
disabled={isSubmitting || !dirty}
isLoading={isSubmitting}
onClick={() => setIsSuccess(false)}
>
Expand All @@ -288,6 +289,7 @@ export const ExtensionRequestForm: React.FC = () => {
<Button
type="primary"
attr="submit"
disabled={isSubmitting || !dirty}
isLoading={isSubmitting}
onClick={() => setIsSuccess(false)}
>
Expand Down

0 comments on commit 23f7667

Please sign in to comment.