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

Disabled form fields are sending its value when submitted #1342

Closed
2 tasks done
GomezIvann opened this issue Oct 20, 2022 · 0 comments · Fixed by #1345
Closed
2 tasks done

Disabled form fields are sending its value when submitted #1342

GomezIvann opened this issue Oct 20, 2022 · 0 comments · Fixed by #1345
Assignees
Labels
bug Something isn't working jira This task is referenced in a story of Jira

Comments

@GomezIvann
Copy link
Collaborator

GomezIvann commented Oct 20, 2022

Describe the bug
Some of our form components are sending their value when they are submitted inside a <form>. This shouldn't be happening since disabled fields must not be sent in a form POST request.

The affected components are:

  • Select
  • Radio Group

To Reproduce
Example:

  1. Create a new React App using create-react-app.
  2. Install the @dxc-technology\halstack-react dependencies and run the app.
  3. Replace your App.jsx component code with:
const App = () => {
  const handlerOnSubmit = (e) => {
    // stop form submission for data validation
    e.preventDefault();
    const formData = new FormData(e.target);
    const formProps = Object.fromEntries(formData);
    console.log(formProps);
  };

  return (
    <DxcInset space="2rem">
      <DxcFlex direction="column" gap="2rem" wrap="wrap">
        <form onSubmit={handlerOnSubmit} action="/user-data" method="post">
          <DxcTextInput
            label="Name"
            name="name"
            placeholder="Write your name"
            defaultValue="Iván"
            disabled
          />
          <DxcCheckbox
            label="Older than 16"
            name="age"
            defaultChecked
            disabled
            value="16"
          />
          <DxcSwitch
            label="Open to work"
            name="openToWork"
            value="opened"
            defaultChecked
            disabled
          />
          <DxcRadioGroup
            label="Gender"
            name="gender"
            options={RDoptions}
            defaultValue="male"
            disabled
          />
          <DxcSlider
            label="Select your height"
            defaultValue={1.70}
            step={0.01}
            minValue={0}
            maxValue={3}
            showInput
            name="height"
            disabled
          />
          <DxcSelect
            name="city"
            label="Select your favourite city"
            placeholder="Choose a city"
            defaultValue="madrid"
            disabled
            options={options}
          />
          <DxcTextarea
            label="Comments"
            name="comments"
            placeholder="Write your comments"
            defaultValue="I like this form."
            disabled
          />
          <DxcButton type="submit" label="Submit" />
        </form>
      </DxcFlex>
    </DxcInset>
  );
};

This basically uses the FormData class to create the object which will be sent when submitting the form.

  1. Open the Console of your browser.
  2. See the log.

Expected behaviour
The console.log should print an empty object, which would then be sent in a POST request. Instead, both Select and Radio Group components are sending their respective values, although they are disabled.

Screenshots
image

Additional context
https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData
Disabled inputs are not submitted

@GomezIvann GomezIvann added bug Something isn't working jira This task is referenced in a story of Jira labels Oct 20, 2022
@GomezIvann GomezIvann self-assigned this Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jira This task is referenced in a story of Jira
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant