grommet-forms proposal
See original GitHub issueThis is a proposal for a new repository for grommet-forms
.
The idea is to make it easier to build typical forms with grommet components. Here is an example of how it could be used:
import { Form, FormField, FormSubmitButton, FormTextInput, FormTextArea } from 'grommet-forms';
class FormExample extends Component {
state = { value: {} }
onSubmit = () => {
const { value } = this.state;
// whatever submitting the form should entail
}
render() {
const { value } = this.state;
return (
<Form
value={value}
onChange={value => this.setState({ value })}
onSubmit={this.onSubmit}
>
<FormField label="Name" name="name" required />
<FormField label="Email" name="email" type="email" />
<FormField label="Employee ID" name="employeeId" validate={/^[0-9]+$/} />
<FormField label="Size" name="size" options={['small', 'medium', 'large']} /> {/* renders RadioButtons */}
<FormField label="Comments" name="comments">
<FormTextArea name="comments" />
</FormField>
<FormSubmitButton label="Update" />
</Form>
);
}
}
FormField.propTypes = {
label: PropTypes.string.description("Human readable label"),
name: PropTypes.string
.description("The key to use within the Form value to store the data.")
.isRequired,
options: PropTypes.arrayOf(PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
])).description("Array of options. If less than four, RadioButtons, otherwise, Select."),
optionLabelKey: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]).description("When options are objects, the key to get the label."),
optionValueKey: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
]).description("When options are objects, the key to get the value."),
required: PropTypes.bool.description("Whether the field is required."),
validate: PropTypes.oneOfType([
PropTypes.object, // regular expression
PropTypes.func,
]).description("Validation rule. Provide a regular expression or a function."),
};
Please let us know if you have any feedback. We’d like some discussion in this issue before proceeding further.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Form - Grommet
Form manages the collective state of its FormFields. There are two primary ways of ... A controlled Form is similar to a controlled...
Read more >Documentation for Grommet - Medium
How do the Grommet docs currently work? Grommet Library. Each component has a doc.js file that contains documentation in the form of a...
Read more >Connector header grommet for an implantable medical device
A penetrable grommet is disposed within the header grommet aperture, ... although proposals have been made to form hermetically sealed housings of a ......
Read more >Grommet Machine Sales Points.pub - Edward Segal Inc -
Manual load, machine punches the hole and sets the grommet. • Does not require Self Piercing Grommets. Works with standard Plain and Rolled...
Read more >Dritz 730-33-T 2-Part Eyelets Kit with Tools, Gunmetal, 1/4 ...
Our dress forms offer unique characteristics that make it easier to get a good ... 1/4 Inch Grommet Kit 200 Sets Grommets Eyelets...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Formik is currently best or at least one of the best solutions for forms with React. Maybe instead of creating something new it is better to either just document how to use Formik with Grommet or create simple wrapper for Grommet & Formik ?
I’ve played a little bit with this and -> very nice and thumb up!
However, I’m struggling with e.g. CheckBox. If used as component= parameter - e.g. the label= is rendered twice. The OnChange Method seems to be implemented by user (it could be done with auto-magic in the background).The value itself seems not to be picked up by the submit method.
Beyond that:
i would suggest to have a form with all standard input types, so there is a kind of documentation for usage.