Creates a DOM form from your options object using vanilla js
Simple form creator is available as an npm package.
npm install simple-form-creator
Include the module in your script.
import simpleFormCreator from 'simple-form-creator';
Create an object containing the form's settings:
- formId (form's id, if not provided, defaults to random string of characters)
- action (action url, if not provided, defaults to empty string
- method (GET, POST, ... - if not provided, defaults to POST)
- formData (data to fill the form with, if not provided, defaults to empty object)
Example:
const formObject = {
'formId': 'myNewForm123',
'action': 'http://mydomain.com/example-post',
'method': 'POST',
'formData': {
'firstName': 'John',
'lastName': 'Smith',
'phoneNumber': '+123456789'
}
}
Now create the form
const form = simpleFormCreator(formObject);
Your brand new form is set up. Now you can use it make form post (or get) submits, append it to DOM or what not. Just one example:
form.submit();
- Fork the Simple-form-creator repository on Github
- Clone your fork to your local machine
git clone [email protected]:<yourname>/simple-form-creator.git
- Create a branch
git checkout -b my-topic-branch
- Make your changes and add tests for them, lint, test then push to to github with
git push --set-upstream origin my-topic-branch
. - Visit github and make your pull request.
- Install
npm install
- Lint
npm run lint
- Test
npm test
- Build
npm run build
Please follow the coding style of the current code base.
Simple-form-creator uses eslint, so if possible, enable linting in your editor to get realtime feedback.
The linting rules can be run manually with npm run lint
.