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

Add Form section pattern #334

Merged
merged 6 commits into from
Jun 16, 2019
Merged

Add Form section pattern #334

merged 6 commits into from
Jun 16, 2019

Conversation

jaronheard
Copy link
Contributor

@jaronheard jaronheard commented Jun 13, 2019

This demonstrates a potential pattern for form sections. It also shows an example using ChangePassword.

If you pass a an array of section names as a prop to Form, then it will give you back a formSections object.

Like so:

// each field in the fields object has a section, either of the following
// section: "userInfo"
// section: "passwordInfo"

<Form fields={fields} sections={["userInfo","passwordInfo"]} ...>

Then in the form page, where you'd use form, instead you'd use formSections.userInfo and formSections.passwordInfo.

Next steps are:

  • add tests
  • update readme

@jaronheard jaronheard changed the title Merge pull request #327 from hackoregon/route-put-contribution-gh-238 Add Form section pattern Jun 13, 2019
Copy link
Collaborator

@andrewbiang888 andrewbiang888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jaronheard is there a way to view this form? Is it in storybook?

@@ -7,20 +7,23 @@ import PasswordField from "../Fields/PasswordField";
const fields = {
oldPassword: {
label: "Old Password",
section: "oldPassword",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jaronheard, this seems like a good format. Does section need to be defined? is there a fallback if there is only one section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Section doesn't need to be defined in fields (though there's probably some ways to break it right now, need to add tests)

Form takes an optional sections prop array of sections, and returns form and formSections

</React.Fragment>
);

const formSections =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you walk me through the formSection is doing here. I see that you are returning children(form, formSections) further down. I'm getting lost in how it's building together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically --
iterate over each section in the sections prop array (e.g. ["sectionOne","sectionTwo"]) and return a formSections object that looks like this:

{
  sectionOne: { // all `fields` with section === `sectionOne`}
  sectionTwo: { // all `fields` with section === `sectionTwo`}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. So we are expecting a consistent naming convention of sectionNUMBER? Is it making sure sectionOne comes before sectionTwo, and sectionTwo comes before sectionThree?

@jaronheard
Copy link
Contributor Author

@andrewbiang888 yes, the ChangePassword page in Storybook is using this. Though it doesn't look at all different than it did before. If you wrapped formSection.oldPassword and formSection.newPassword you could style them differently.

@jaronheard
Copy link
Contributor Author

jaronheard commented Jun 14, 2019 via email

Copy link
Collaborator

@andrewbiang888 andrewbiang888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, great start.

@andrewbiang888 andrewbiang888 merged commit 6764c10 into develop Jun 16, 2019
@jaronheard jaronheard deleted the add-form-sections branch March 1, 2020 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants