Skip to content

Commit

Permalink
v0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
amirmohsen committed Sep 12, 2017
1 parent 5114ad0 commit 8884a8a
Show file tree
Hide file tree
Showing 47 changed files with 6,276 additions and 1,072 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
node_modules/
dist/
npm-debug.log
.idea
node_modules
dist
npm-debug.log
yarn-error.log
7 changes: 1 addition & 6 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
src/
examples/
docs/
tasks/
.gitignore
.idea
src
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.0.2 - 2016-09-12
## [0.0.3] - 2017-09-12
### Refactored
- The entire library

## [0.0.2] - 2016-09-12
### Fixed
- README file now has code highlighting.

## 0.0.1 - 2016-09-10
### Added
- Initial release.
- Initial release.

[0.0.3]: https://github.com/amirmohsen/flexform/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/amirmohsen/flexform/compare/v0.0.1...v0.0.2
22 changes: 1 addition & 21 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
MIT License

Copyright (c) 2016 Amir Mohsen Abdolrazaghi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
UNLICENSED
142 changes: 1 addition & 141 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,141 +1 @@
# Flex Form

Flex Form is a JavaScript library for generating forms from Mongoose Schemas, using React components.
**Note: This library is in a working condition. However, since it is the early days, things may rapidly change.**

## Installation

Make sure React and Mongoose are installed in your project.
Mongoose has an npm package which has a lot of issues in the browser.
For now, the CDN version is recommended.

```
npm install --save flexform
```

## Usage

The followings can be imported from the `flexform` module.

```js
import FlexForm, {Field, FlexFormError, TypeNoMatchError, types, setType} from 'flexform';
```

### Field component

Flex Form as the name suggests, is about providing flexibility.
Unlike other form generators, it doesn't come with built-in fields, but it allows you to create any number of your own fields, both simple and complex.

All fields that you create must extend the `Field` component.
Here's a simple text field. Check the `examples` folder for more.

```js
import React from 'react';
import {Field} from 'flexform';

export default class Text extends Field {

onChange = (e) => {
this.save(e.target.value);
};

render() {
return (
<input type="text" value={this.getData()} onChange={this.onChange} />
)
}
}
```

### FlexForm component

Provided with the following schema:

```js
export default new mongoose.Schema({
profile: {
name: String,
age: Number,
higherEd: Boolean
},
children: [
{
name: String,
gender: {
type: String,
default: 'female'
}
}
]
});
```

We can easily generate a form (with or without existing data):

```js
import React, {Component} from 'react';
import schema from './schema';
import FlexForm from 'flexform';
import {GroupList, Group, Text, Radio, Checkbox} from '../BasicFields';

export default class Simple extends Component {

onChange = (data) => {
this.setState({
data
});
};

constructor(props) {
super(props);
this.state = {
data: {
profile: {
age: 30
},
children: [
{
name: 'Julie'
},
{
name: 'Ashley'
}
]
}
};
}

render() {
return (
<FlexForm schema={schema} data={this.state.data} onInit={this.onChange} onChange={this.onChange} >
<Group path="profile">
Name: <Text path="name"/>
Age: <Text path="age"/>
Has Higher Education Degree? <Checkbox path="higherEd"/>
</Group>
Children:
<GroupList path="children">
<Group path="$">
Name: <Text path="name"/>
Gender:
Male: <Radio value="male" path="gender" />
Female: <Radio value="female" path="gender" />
</Group>
</GroupList>
<pre>
{JSON.stringify(this.state.data, null, '\t')}
</pre>
</FlexForm>
);
}
}
```

### Other exports

Other exports can be used for further customization, such as extra types.
For more information, clone this repo and run `npm run dev` to get the example up.

## License

Flex Form is MIT licensed.
# FlexForm
19 changes: 19 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
process.on('unhandledRejection', (reason, p) => { throw reason });

require('babel-polyfill');
const loader = require('flexbuilder').default;
const argv = require('yargs').argv;

loader({
root: __dirname,
dev: !!argv.dev,
library: 'FlexForm',
sources: {
client: {
index: './src'
},
server: {
index: './src'
}
}
});
1 change: 1 addition & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/client');
Empty file removed docs/.gitkeep
Empty file.
26 changes: 0 additions & 26 deletions examples/BasicFields/Checkbox.js

This file was deleted.

13 changes: 0 additions & 13 deletions examples/BasicFields/Group.js

This file was deleted.

31 changes: 0 additions & 31 deletions examples/BasicFields/GroupList.js

This file was deleted.

21 changes: 0 additions & 21 deletions examples/BasicFields/Radio.js

This file was deleted.

15 changes: 0 additions & 15 deletions examples/BasicFields/Text.js

This file was deleted.

5 changes: 0 additions & 5 deletions examples/BasicFields/index.js

This file was deleted.

Loading

0 comments on commit 8884a8a

Please sign in to comment.