├── docs ├── pages │ ├── index.js │ ├── examples │ │ ├── arrays │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── index.js │ │ ├── refs │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── simple │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── server.js │ │ │ ├── index.html │ │ │ ├── index.md │ │ │ └── index.js │ │ ├── all-widgets │ │ │ ├── .gitignore │ │ │ ├── index.md │ │ │ ├── spec.json │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── change-layout │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── custom-themes │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ ├── index.js │ │ │ └── index.md │ │ ├── validation │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── combining-schemas │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── initial-values │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.md │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── custom-field-validation │ │ │ ├── .gitignore │ │ │ ├── spec.json │ │ │ ├── index.html │ │ │ ├── webpack.config.js │ │ │ ├── index.md │ │ │ ├── server.js │ │ │ └── index.js │ │ ├── index.md │ │ └── spec.json │ ├── spec.json │ └── index.md └── images │ └── example-liform-react.png ├── .eslintignore ├── .eslintrc ├── .babelrc ├── src ├── __tests__ │ ├── tempPolyfills.js │ ├── test-utils.js │ ├── setup.js │ ├── compileSchema.spec.js │ ├── themes.bootstrap3.TextareaWidget.spec.js │ ├── processSubmitErrors.spec.js │ ├── themes.bootstrap3.compatibleDateWidget.spec.js │ ├── themes.bootstrap3.ArrayWidget.spec.js │ ├── themes.bootstrap3.CompatibleDateTimeWidget.spec.js │ ├── themes.bootstrap3.CheckboxWidget.spec.js │ ├── themes.bootstrap3.StringWidget.spec.js │ ├── themes.bootstrap3.NumberWidget.spec.js │ ├── themes.bootstrap3.FileWidget.spec.js │ ├── themes.bootstrap3.UrlWidget.spec.js │ ├── themes.bootstrap3.DateWidget.spec.js │ ├── themes.bootstrap3.SearchWidget.spec.js │ ├── themes.bootstrap3.TimeWidget.spec.js │ ├── themes.bootstrap3.ColorWidget.spec.js │ ├── themes.bootstrap3.EmailWidget.spec.js │ ├── themes.bootstrap3.PasswordWidget.spec.js │ ├── themes.bootstrap3.DateTimeWidget.spec.js │ ├── themes.bootstrap3.ChoiceWidget.spec.js │ ├── themes.bootstrap3.MoneyWidget.spec.js │ ├── themes.bootstrap3.PercentWidget.spec.js │ ├── renderFields.spec.js │ ├── createLiformSpec.spec.js │ └── buildSyncValidation.spec.js ├── themes │ ├── bootstrap3 │ │ ├── DateWidget.js │ │ ├── TimeWidget.js │ │ ├── UrlWidget.js │ │ ├── SearchWidget.js │ │ ├── StringWidget.js │ │ ├── PasswordWidget.js │ │ ├── DateTimeWidget.js │ │ ├── NumberWidget.js │ │ ├── ColorWidget.js │ │ ├── EmailWidget.js │ │ ├── ObjectWidget.js │ │ ├── DateSelector.js │ │ ├── CheckboxWidget.js │ │ ├── TextareaWidget.js │ │ ├── BaseInputWidget.js │ │ ├── FileWidget.js │ │ ├── PercentWidget.js │ │ ├── MoneyWidget.js │ │ ├── index.js │ │ ├── ChoiceExpandedWidget.js │ │ ├── ChoiceWidget.js │ │ ├── oneOfChoiceWidget.js │ │ ├── ChoiceMultipleExpandedWidget.js │ │ ├── ArrayWidget.js │ │ ├── CompatibleDateWidget.js │ │ └── CompatibleDateTimeWidget.js │ └── index.js ├── renderFields.js ├── LICENSE ├── compileSchema.js ├── processSubmitErrors.js ├── renderField.js ├── index.js └── buildSyncValidation.js ├── .npmignore ├── .gitignore ├── .travis.yml ├── LICENSE ├── webpack.config.js ├── README.md └── package.json /docs/pages/index.js: -------------------------------------------------------------------------------- 1 | console.log("hola"); 2 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/index.js: -------------------------------------------------------------------------------- 1 | console.log("hola"); 2 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/index.md: -------------------------------------------------------------------------------- 1 | Here we go. 2 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-themes/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/validation/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "index" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/.gitignore: -------------------------------------------------------------------------------- 1 | bundle.js 2 | -------------------------------------------------------------------------------- /docs/pages/examples/index.md: -------------------------------------------------------------------------------- 1 | ##hi 2 | 3 | a ritual *salutation* 4 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Refs" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Examples" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Arrays" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Simple form" 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | webpack.config*.js 2 | src/__tests__ 3 | node_modules 4 | examples -------------------------------------------------------------------------------- /docs/pages/examples/validation/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Validation" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "All the widgets" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Change layout" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-themes/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Custom themes" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Initial values" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Combining schemas" 3 | } 4 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Custom field validation" 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "react-app", 3 | "rules": { 4 | "jsx-a11y/href-no-hash": 0 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /docs/images/example-liform-react.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Limenius/liform-react/HEAD/docs/images/example-liform-react.png -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-0", "react"], 3 | "plugins": ["transform-object-rest-spread", "lodash"] 4 | } 5 | 6 | -------------------------------------------------------------------------------- /src/__tests__/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const raf = global.requestAnimationFrame = (cb) => { 2 | setTimeout(cb, 0) 3 | } 4 | 5 | export default raf -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/index.md: -------------------------------------------------------------------------------- 1 | Simply by providing an object that matches our schema as the `prop` `initialValues` we can provide initial values. 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | examples 2 | scripts 3 | docs 4 | .babelrc 5 | .eslint* 6 | .idea 7 | .editorconfig 8 | .npmignore 9 | .nyc_output 10 | .travis.yml 11 | webpack.* 12 | coverage 13 | 14 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/index.md: -------------------------------------------------------------------------------- 1 | We can use `$ref` to include snippets defined elsewhere, to avoid repeated definitions. 2 | 3 | In this case we are defining the `address` and later using it. 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | dist 4 | lib 5 | es 6 | .DS_Store 7 | yarn.lock 8 | .nyc_output/ 9 | coverage/ 10 | examples/bundle* 11 | package-lock.json 12 | built_docs/ 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | before_install: 4 | - npm install -g npm@latest 5 | 6 | node_js: 7 | - "8" 8 | - "6" 9 | 10 | script: 11 | - npm run lint 12 | - npm test 13 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/index.md: -------------------------------------------------------------------------------- 1 | Lifrm react supports oneOf and allOf, that are ways of combining schemas. [Read about them here](https://spacetelescope.github.io/understanding-json-schema/reference/combining.html). 2 | 3 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/index.md: -------------------------------------------------------------------------------- 1 | What if instead of writing our own widgets we want to change the form's layout? 2 | The default layout has a simple submit button with the text "Submit" and shows global errors just above of it. 3 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/DateWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const DateWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default DateWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/TimeWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const TimeWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default TimeWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/UrlWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const UrlWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default UrlWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/SearchWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const SearchWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default SearchWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/StringWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const StringWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default StringWidget; 9 | -------------------------------------------------------------------------------- /docs/pages/index.md: -------------------------------------------------------------------------------- 1 | #Doc root 2 | 3 | This is a placeholder of the main page of the docs, that will be generated soon and will replace the current documentation system. 4 | 5 | For now, just go to the current documentation https://limenius.github.io/liform-react/#/ 6 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/PasswordWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const PasswordWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default PasswordWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/DateTimeWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const DateTimeWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default DateTimeWidget; 9 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/NumberWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseInputWidget from "./BaseInputWidget"; 3 | 4 | const NumberWidget = props => { 5 | return ; 6 | }; 7 | 8 | export default NumberWidget; 9 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/server.js: -------------------------------------------------------------------------------- 1 | var express = require('express') 2 | 3 | var app = express() 4 | 5 | app.use(express.static('./')) 6 | 7 | app.listen(3000, 'localhost', function(err) { 8 | if (err) { 9 | console.log(err) 10 | return 11 | } 12 | 13 | console.log('Listening at http://localhost:3000') 14 | }) 15 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/index.md: -------------------------------------------------------------------------------- 1 | Arrays are just regular items. Currently, the default theme has two ways of represent them (you can of course write your own widget for arrays). 2 | 3 | An array of other objects will be presented as a collection where you can add more items or remove them. 4 | 5 | An array of strings with the restriction `uniqueItems` will be presented as multiple choice list. 6 | -------------------------------------------------------------------------------- /docs/pages/examples/validation/index.md: -------------------------------------------------------------------------------- 1 | Liform relies by default on [*ajv*](https://github.com/epoberezkin/ajv) to perform on blur validation. You can pass your custom validator using the `prop` `validate`. 2 | 3 | For validation on submit you can provide a validator using the `onSubmit` `prop`. For this, check the documentation of *redux-form*. This example adapted directly from its documentation. 4 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/index.md: -------------------------------------------------------------------------------- 1 | In this example we are basically setting up Redux with redux-form and using the `Liform` component with a simple json-schema. 2 | 3 | The form state will be mounted by default on the key `form` of the Redux state. If you provide a `formKey` prop to the `Liform` component, it will be used instead. Or, with a lower priority, you can provide a `title` property in the root object of oyour schema. 4 | 5 | -------------------------------------------------------------------------------- /docs/pages/examples/validation/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-themes/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-themes/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/validation/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: ["./index"], 5 | output: { 6 | filename: "bundle.js", 7 | path: "/" 8 | }, 9 | module: { 10 | loaders: [ 11 | { 12 | test: /\.jsx?/, 13 | loaders: [ 'babel-loader' ], 14 | include: path.join(__dirname, './'), 15 | exclude: /node_modules/ 16 | }, 17 | ] 18 | } 19 | }; 20 | 21 | module.exports = config; 22 | -------------------------------------------------------------------------------- /src/__tests__/test-utils.js: -------------------------------------------------------------------------------- 1 | import React, { Children } from "react"; 2 | import { createStore, combineReducers } from "redux"; 3 | import { Provider } from "react-redux"; 4 | import { reducer as formReducer } from "redux-form"; 5 | 6 | const makeStore = () => createStore(combineReducers({ form: formReducer })); 7 | 8 | const FormFrame = props => { 9 | const store = makeStore(); 10 | return {Children.only(props.children)}; 11 | }; 12 | 13 | export { FormFrame }; 14 | -------------------------------------------------------------------------------- /src/__tests__/setup.js: -------------------------------------------------------------------------------- 1 | import raf from './tempPolyfills' 2 | import Enzyme, { shallow, render, mount } from 'enzyme'; 3 | import Adapter from 'enzyme-adapter-react-16'; 4 | 5 | // React 16 Enzyme adapter 6 | Enzyme.configure({ adapter: new Adapter() }); 7 | 8 | // Make Enzyme functions available in all test files without importing 9 | global.shallow = shallow; 10 | global.render = render; 11 | global.mount = mount; 12 | 13 | // Fail tests on any warning 14 | console.error = message => { 15 | throw new Error(message); 16 | }; -------------------------------------------------------------------------------- /src/themes/bootstrap3/ColorWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import BaseInputWidget from "./BaseInputWidget"; 4 | 5 | const ColorWidget = props => { 6 | return ; 7 | }; 8 | 9 | BaseInputWidget.propTypes = { 10 | schema: PropTypes.object.isRequired, 11 | type: PropTypes.string.isRequired, 12 | required: PropTypes.bool, 13 | fieldName: PropTypes.string, 14 | label: PropTypes.string 15 | }; 16 | 17 | export default ColorWidget; 18 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/EmailWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import BaseInputWidget from "./BaseInputWidget"; 4 | 5 | const EmailWidget = props => { 6 | return ; 7 | }; 8 | 9 | EmailWidget.propTypes = { 10 | schema: PropTypes.object.isRequired, 11 | fieldName: PropTypes.string, 12 | label: PropTypes.string, 13 | theme: PropTypes.object, 14 | multiple: PropTypes.bool, 15 | required: PropTypes.bool 16 | }; 17 | 18 | export default EmailWidget; 19 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/index.md: -------------------------------------------------------------------------------- 1 | To provide custom validation, there are two options: 2 | 3 | * Provide a validator in the `validate` prop of `Liform`. Check out [the default validator](https://github.com/Limenius/liform-react/blob/master/src/buildSyncValidation.js). You can provide a version based on `ajv` or roll your own. 4 | * Provide a validator in a new widget. To do so you have to extend or provide a new theme and implement the validator in the field. You can check the documentation of redux-form to know how to do this. Below you have an example of this. 5 | -------------------------------------------------------------------------------- /docs/pages/examples/arrays/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/refs/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/all-widgets/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/validation/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/change-layout/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-themes/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /docs/pages/examples/custom-field-validation/server.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var express = require('express') 3 | var webpack = require('webpack') 4 | var config = require('./webpack.config.js') 5 | 6 | var app = express() 7 | var compiler = webpack(config, () => {}) 8 | 9 | app.use(express.static('./')) 10 | //app.get('*', function(req, res) { 11 | // res.sendFile(path.join(__dirname, 'index.html')) 12 | //}) 13 | 14 | app.listen(3000, 'localhost', function(err) { 15 | if (err) { 16 | console.log(err) 17 | return 18 | } 19 | 20 | console.log('Listening at http://localhost:3000') 21 | }) 22 | -------------------------------------------------------------------------------- /src/__tests__/compileSchema.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import compileSchema from "../compileSchema"; 3 | 4 | describe("createLiform", () => { 5 | const schema = { 6 | definitions: { 7 | nameref: { 8 | type: "string" 9 | } 10 | }, 11 | title: "A schema", 12 | properties: { 13 | name: { 14 | $ref: "#/definitions/nameref" 15 | } 16 | } 17 | }; 18 | 19 | it("should resolve $refs", () => { 20 | const schemaCompiled = compileSchema(schema); 21 | expect(schemaCompiled.properties.name).toHaveProperty("type"); 22 | expect(schemaCompiled.properties.name.type).toEqual("string"); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/ObjectWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import renderFields from "../../renderFields"; 4 | 5 | const Widget = props => { 6 | return ( 7 |
8 | {props.label && {props.label}} 9 | {renderFields( 10 | props.schema, 11 | props.theme, 12 | props.fieldName && props.fieldName + ".", 13 | props.context 14 | )} 15 |
16 | ); 17 | }; 18 | 19 | Widget.propTypes = { 20 | schema: PropTypes.object.isRequired, 21 | fieldName: PropTypes.string, 22 | label: PropTypes.string, 23 | theme: PropTypes.object, 24 | context: PropTypes.object 25 | }; 26 | 27 | export default Widget; 28 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/DateSelector.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const DateSelector = props => { 4 | return ( 5 | 26 | ); 27 | }; 28 | 29 | export default DateSelector; 30 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.TextareaWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("TextareaWidget", () => { 8 | it("should render a form with a textarea widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "textarea" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("textarea").length).toEqual(1); 28 | expect(wrapper.find("textarea").prop('id')).toEqual('field-field'); 29 | expect(wrapper.find("label").prop('for')).toEqual('field-field'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /src/__tests__/processSubmitErrors.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import processSubmitErrors from "../processSubmitErrors"; 3 | import { SubmissionError } from "redux-form"; 4 | 5 | describe("processSubmitErrors", () => { 6 | it("raises exception if there is an error", () => { 7 | const response = { 8 | code: null, 9 | message: "Validation Failed", 10 | errors: { 11 | children: { 12 | name: { 13 | errors: ["This value should not be equal to 'Mary'."] 14 | }, 15 | color: [] 16 | } 17 | } 18 | }; 19 | expect(function() { 20 | processSubmitErrors(response); 21 | }).toThrow(SubmissionError); 22 | }); 23 | 24 | it("does not raise exception if there is no error", () => { 25 | const response = { 26 | code: null, 27 | message: "Validation Failed" 28 | }; 29 | expect(function() { 30 | processSubmitErrors(response); 31 | }).not.toThrow(SubmissionError); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/renderFields.js: -------------------------------------------------------------------------------- 1 | import renderField from "./renderField"; 2 | 3 | export const isRequired = (schema, fieldName) => { 4 | if (!schema.required) { 5 | return false; 6 | } 7 | return schema.required.indexOf(fieldName) !== -1; 8 | }; 9 | 10 | const renderFields = (schema, theme, prefix = null, context = {}) => { 11 | let props = []; 12 | for (let i in schema.properties) { 13 | props.push({ prop: i, propertyOrder: schema.properties[i].propertyOrder }); 14 | } 15 | props = props.sort((a, b) => { 16 | if (a.propertyOrder > b.propertyOrder) { 17 | return 1; 18 | } else if (a.propertyOrder < b.propertyOrder) { 19 | return -1; 20 | } else { 21 | return 0; 22 | } 23 | }); 24 | return props.map(item => { 25 | const name = item.prop; 26 | const field = schema.properties[name]; 27 | return renderField( 28 | field, 29 | name, 30 | theme, 31 | prefix, 32 | context, 33 | isRequired(schema, name) 34 | ); 35 | }); 36 | }; 37 | 38 | export default renderFields; 39 | -------------------------------------------------------------------------------- /docs/pages/examples/simple/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import { createStore, combineReducers } from 'redux' 4 | import { reducer as formReducer } from 'redux-form' 5 | import { Provider } from 'react-redux' 6 | import Liform from '../../../../src/' 7 | 8 | const Demo = () => { 9 | const reducer = combineReducers({ form: formReducer }) 10 | const store = createStore(reducer) 11 | const schema = { 12 | 'type':'object', 13 | 'properties': { 14 | 'title': { 'type':'string', 'title': 'Title' }, 15 | 'type': { 'enum':[ 'One','Two' ], 'type':'string', 'title': 'Select a type' }, 16 | 'color': { 'type':'string', 'widget': 'color', 'title': 'In which color' }, 17 | 'checkbox': { 'type':'boolean', 'title': 'I agree with your terms' } 18 | } 19 | } 20 | return ( 21 | 22 | {console.log(v)}}/> 23 | 24 | ) 25 | } 26 | 27 | ReactDOM.render( 28 | , 29 | document.getElementById('placeholder') 30 | ) 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Nacho Martín 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Nacho Martín 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/compileSchema.js: -------------------------------------------------------------------------------- 1 | function isObject(thing) { 2 | return typeof thing === "object" && thing !== null && !Array.isArray(thing); 3 | } 4 | 5 | function compileSchema(schema, root) { 6 | if (!root) { 7 | root = schema; 8 | } 9 | let newSchema; 10 | 11 | if (isObject(schema)) { 12 | newSchema = {}; 13 | for (let i in schema) { 14 | if (schema.hasOwnProperty(i)) { 15 | if (i === "$ref") { 16 | newSchema = compileSchema(resolveRef(schema[i], root), root); 17 | } else { 18 | newSchema[i] = compileSchema(schema[i], root); 19 | } 20 | } 21 | } 22 | return newSchema; 23 | } 24 | 25 | if (Array.isArray(schema)) { 26 | newSchema = []; 27 | for (let i = 0; i < schema.length; i += 1) { 28 | newSchema[i] = compileSchema(schema[i], root); 29 | } 30 | return newSchema; 31 | } 32 | 33 | return schema; 34 | } 35 | 36 | function resolveRef(uri, schema) { 37 | uri = uri.replace("#/", ""); 38 | const tokens = uri.split("/"); 39 | const tip = tokens.reduce((obj, token) => obj[token], schema); 40 | 41 | return tip; 42 | } 43 | 44 | export default compileSchema; 45 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require("path"); 2 | 3 | var config = { 4 | entry: { 5 | simple: "./docs/pages/examples/simple/index", 6 | "all-widgets": "./docs/pages/examples/all-widgets/index", 7 | "arrays": "./docs/pages/examples/arrays/index", 8 | "change-layout": "./docs/pages/examples/change-layout/index", 9 | "combining-schemas": "./docs/pages/examples/combining-schemas/index", 10 | "custom-field-validation": "./docs/pages/examples/custom-field-validation/index", 11 | "custom-themes": "./docs/pages/examples/custom-themes/index", 12 | "initial-values": "./docs/pages/examples/initial-values/index", 13 | "refs": "./docs/pages/examples/refs/index", 14 | "validation": "./docs/pages/examples/validation/index", 15 | }, 16 | output: { 17 | filename: "[name]/bundle.js", 18 | path: path.resolve(__dirname, "./docs/pages/examples/") 19 | }, 20 | module: { 21 | loaders: [ 22 | { 23 | test: /\.jsx?/, 24 | loaders: [ 'babel-loader' ], 25 | exclude: /node_modules/ 26 | }, 27 | { 28 | test: /\.json?/, 29 | loaders: [ 'json-loader' ], 30 | }, 31 | ] 32 | } 33 | }; 34 | 35 | module.exports = config; 36 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.compatibleDateWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import { extractDateToken } from "../themes/bootstrap3/CompatibleDateWidget.js"; 3 | import React from "react"; 4 | import Liform from "../"; 5 | import { FormFrame } from "./test-utils"; 6 | import { shallow, mount, render } from "enzyme"; 7 | 8 | describe("CompatibleDateWidget", () => { 9 | it("on null extracted value is empty", () => { 10 | expect(extractDateToken(null)).toBe(""); 11 | }); 12 | it("on invalid format extracted value is empty", () => { 13 | expect(extractDateToken("lala-land")).toBe(""); 14 | }); 15 | it("can extract month", () => { 16 | expect(extractDateToken("1967-04-03", 1)).toBe("04"); 17 | }); 18 | 19 | it("should render a form", () => { 20 | const schema = { 21 | title: "A schema", 22 | properties: { 23 | date: { 24 | type: "string", 25 | widget: "compatible-date" 26 | } 27 | } 28 | }; 29 | 30 | const Component = ( 31 | 32 | 33 | 34 | ); 35 | const wrapper = render(Component); 36 | expect(wrapper.find("select").length).toEqual(3); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.ArrayWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("ArrayWidget", () => { 8 | it("should render a form with children", () => { 9 | const schema = { 10 | title: "A Schema", 11 | properties: { 12 | tasks: { 13 | type: "array", 14 | title: "A list of objects", 15 | items: { 16 | type: "object", 17 | properties: { 18 | name: { 19 | type: "string", 20 | title: "Name of the Task" 21 | }, 22 | dueTo: { 23 | type: "string", 24 | title: "Due To", 25 | widget: "datetime", 26 | format: "date-time" 27 | } 28 | } 29 | } 30 | } 31 | } 32 | }; 33 | 34 | const Component = ( 35 | 36 | 37 | 38 | ); 39 | 40 | const wrapper = render(Component); 41 | 42 | expect(wrapper.find(".btn").length).toEqual(2); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.CompatibleDateTimeWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import { extractDateTimeToken } from "../themes/bootstrap3/CompatibleDateTimeWidget.js"; 3 | import React from "react"; 4 | import Liform from "../"; 5 | import { FormFrame } from "./test-utils"; 6 | import { shallow, mount, render } from "enzyme"; 7 | 8 | describe("CompatibleDateTimeWidget", () => { 9 | it("on null extracted value is empty", () => { 10 | expect(extractDateTimeToken(null)).toBe(""); 11 | }); 12 | it("on invalid format extracted value is empty", () => { 13 | expect(extractDateTimeToken("lala-land")).toBe(""); 14 | }); 15 | it("can extract month", () => { 16 | expect(extractDateTimeToken("1967-04-03T23:04:16", 1)).toBe("04"); 17 | }); 18 | 19 | it("should render a form", () => { 20 | const schema = { 21 | title: "A schema", 22 | properties: { 23 | date: { 24 | type: "string", 25 | widget: "compatible-datetime" 26 | } 27 | } 28 | }; 29 | 30 | const Component = ( 31 | 32 | 33 | 34 | ); 35 | const wrapper = render(Component); 36 | 37 | expect(wrapper.find("select").length).toEqual(6); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.CheckboxWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("CheckboxWidget", () => { 8 | it("should render a form with a checkbox", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "boolean" 14 | } 15 | } 16 | }; 17 | 18 | const Component = ( 19 | 20 | 21 | 22 | ); 23 | 24 | const wrapper = render(Component); 25 | expect(wrapper.find("input[type=checkbox]").length).toEqual(1); 26 | }); 27 | it("required gives the input the required attribute", () => { 28 | const schema = { 29 | title: "A schema", 30 | properties: { 31 | field: { 32 | type: "boolean" 33 | } 34 | }, 35 | required: ["field"] 36 | }; 37 | 38 | const Component = ( 39 | 40 | 41 | 42 | ); 43 | 44 | const wrapper = render(Component); 45 | 46 | expect(wrapper.find("input[required]").length).toEqual(1); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.StringWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("StringWidget", () => { 8 | it("should render a form with a type text widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string" 14 | } 15 | } 16 | }; 17 | 18 | const Component = ( 19 | 20 | 21 | 22 | ); 23 | 24 | const wrapper = render(Component); 25 | 26 | expect(wrapper.find("input[type=text]").length).toEqual(1); 27 | }); 28 | it("required gives the input the required attribute", () => { 29 | const schema = { 30 | title: "A schema", 31 | properties: { 32 | field: { 33 | type: "string" 34 | } 35 | }, 36 | required: ["field"] 37 | }; 38 | 39 | const Component = ( 40 | 41 | 42 | 43 | ); 44 | 45 | const wrapper = render(Component); 46 | 47 | expect(wrapper.find("input[required]").length).toEqual(1); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /docs/pages/examples/initial-values/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import { createStore, combineReducers } from 'redux' 4 | import { reducer as formReducer } from 'redux-form' 5 | import { Provider } from 'react-redux' 6 | import Liform from '../../../../src/' 7 | 8 | const Demo = () => { 9 | const reducer = combineReducers({ form: formReducer }) 10 | const store = createStore(reducer) 11 | const schema = { 12 | 'type':'object', 13 | 'properties': { 14 | 'title': { 'type':'string', 'title': 'Title' }, 15 | 'type': { 'enum':[ 'One','Two' ], 'type':'string', 'title': 'Select a type' }, 16 | 'color': { 'type':'string', 'widget': 'color', 'title': 'In which color' }, 17 | 'checkbox': { 'type':'boolean', 'title': 'I agree with your terms' } 18 | } 19 | } 20 | const initialValues = { 21 | title : 'I am an initial title value', 22 | type : 'One', 23 | color : '#e4f533', 24 | } 25 | return ( 26 | 27 | {console.log(v)}}/> 28 | 29 | ) 30 | } 31 | 32 | ReactDOM.render( 33 | , 34 | document.getElementById('placeholder') 35 | ) 36 | 37 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.NumberWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("NumberWidget", () => { 8 | it("should render a form with a number input", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "number" 14 | } 15 | } 16 | }; 17 | 18 | const Component = ( 19 | 20 | 21 | 22 | ); 23 | 24 | const wrapper = render(Component); 25 | 26 | expect(wrapper.find("input[type=number]").length).toEqual(1); 27 | }); 28 | it("required gives the input the required attribute", () => { 29 | const schema = { 30 | title: "A schema", 31 | properties: { 32 | field: { 33 | type: "string", 34 | widget: "number" 35 | } 36 | }, 37 | required: ["field"] 38 | }; 39 | 40 | const Component = ( 41 | 42 | 43 | 44 | ); 45 | 46 | const wrapper = render(Component); 47 | 48 | expect(wrapper.find("input[required]").length).toEqual(1); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.FileWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("FileWidget", () => { 8 | it("should render a form with a file input", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "file" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=file]").length).toEqual(1); 28 | }); 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "file" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.UrlWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("EmailWidget", () => { 8 | it("should render a form with a type url input", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "url" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=url]").length).toEqual(1); 28 | }); 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "url" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.DateWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("DateWidget", () => { 8 | it("should render a form with a type date widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "date" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | expect(wrapper.find("input[type=date]").length).toEqual(1); 27 | }); 28 | 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "date" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.SearchWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("SearchWidget", () => { 8 | it("should render a form with a text input", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "search" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=search]").length).toEqual(1); 28 | }); 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "search" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.TimeWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("TimeWidget", () => { 8 | it("should render a form with a type time widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "time" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=time]").length).toEqual(1); 28 | }); 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "time" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.ColorWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("ColorWidget", () => { 8 | it("should render a form with a type color widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | color: { 13 | type: "string", 14 | widget: "color" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | expect(wrapper.find("input[type=color]").length).toEqual(1); 27 | }); 28 | 29 | it("required gives the input the required attribute", () => { 30 | const schema = { 31 | title: "A schema", 32 | properties: { 33 | field: { 34 | type: "string", 35 | widget: "color" 36 | } 37 | }, 38 | required: ["field"] 39 | }; 40 | 41 | const Component = ( 42 | 43 | 44 | 45 | ); 46 | 47 | const wrapper = render(Component); 48 | 49 | expect(wrapper.find("input[required]").length).toEqual(1); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.EmailWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("EmailWidget", () => { 8 | it("should render a form with a type email widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "email" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=email]").length).toEqual(1); 28 | }); 29 | 30 | it("required gives the input the required attribute", () => { 31 | const schema = { 32 | title: "A schema", 33 | properties: { 34 | field: { 35 | type: "string", 36 | widget: "email" 37 | } 38 | }, 39 | required: ["field"] 40 | }; 41 | 42 | const Component = ( 43 | 44 | 45 | 46 | ); 47 | 48 | const wrapper = render(Component); 49 | 50 | expect(wrapper.find("input[required]").length).toEqual(1); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.PasswordWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("PasswordWidget", () => { 8 | it("should render a form with a type password widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "password" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=password]").length).toEqual(1); 28 | }); 29 | 30 | it("required gives the input the required attribute", () => { 31 | const schema = { 32 | title: "A schema", 33 | properties: { 34 | field: { 35 | type: "string", 36 | widget: "password" 37 | } 38 | }, 39 | required: ["field"] 40 | }; 41 | 42 | const Component = ( 43 | 44 | 45 | 46 | ); 47 | 48 | const wrapper = render(Component); 49 | 50 | expect(wrapper.find("input[required]").length).toEqual(1); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.DateTimeWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("DateTimeWidget", () => { 8 | it("should render a form with a type datetime widget", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | datetime: { 13 | type: "string", 14 | widget: "datetime" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=datetime-local]").length).toEqual(1); 28 | }); 29 | 30 | it("required gives the input the required attribute", () => { 31 | const schema = { 32 | title: "A schema", 33 | properties: { 34 | field: { 35 | type: "string", 36 | widget: "datetime" 37 | } 38 | }, 39 | required: ["field"] 40 | }; 41 | 42 | const Component = ( 43 | 44 | 45 | 46 | ); 47 | 48 | const wrapper = render(Component); 49 | 50 | expect(wrapper.find("input[required]").length).toEqual(1); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/processSubmitErrors.js: -------------------------------------------------------------------------------- 1 | import { SubmissionError } from "redux-form"; 2 | import { isEmpty as _isEmpty } from "lodash"; // added for empty check 3 | 4 | const convertToReduxFormErrors = obj => { 5 | let objectWithoutChildrenAndFalseErrors = {}; 6 | Object.keys(obj).map(name => { 7 | if (name === "children") { 8 | objectWithoutChildrenAndFalseErrors = { 9 | ...objectWithoutChildrenAndFalseErrors, 10 | ...convertToReduxFormErrors(obj[name]) 11 | }; 12 | } else { 13 | if (obj[name].hasOwnProperty("children")) { 14 | // if children, take field from it and set them directly as own field 15 | objectWithoutChildrenAndFalseErrors[name] = convertToReduxFormErrors( 16 | obj[name] 17 | ); 18 | } else { 19 | if ( 20 | obj[name].hasOwnProperty("errors") && 21 | !_isEmpty(obj[name]["errors"]) 22 | ) { 23 | // using lodash for empty error check, dont add them if empty 24 | objectWithoutChildrenAndFalseErrors[name] = obj[name]["errors"]; 25 | } 26 | } 27 | } 28 | return null; 29 | }); 30 | return objectWithoutChildrenAndFalseErrors; 31 | }; 32 | 33 | const processSubmitErrors = errors => { 34 | if (errors.hasOwnProperty("errors")) { 35 | errors = convertToReduxFormErrors(errors.errors); 36 | throw new SubmissionError(errors); 37 | } 38 | }; 39 | 40 | export default processSubmitErrors; 41 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.ChoiceWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("ChoiceWidget", () => { 8 | it("should render a form with a select", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | choice: { 13 | type: "string", 14 | enum: ["foo", "bar"] 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | expect(wrapper.find("select").length).toEqual(1); 27 | expect(wrapper.find("option").length).toEqual(3); 28 | }); 29 | 30 | it("required renders no extra field", () => { 31 | const schema = { 32 | title: "A schema", 33 | properties: { 34 | choice: { 35 | type: "string", 36 | enum: ["foo", "bar"] 37 | } 38 | }, 39 | required: ["choice"] 40 | }; 41 | 42 | const Component = ( 43 | 44 | 45 | 46 | ); 47 | 48 | const wrapper = render(Component); 49 | expect(wrapper.find("select").length).toEqual(1); 50 | expect(wrapper.find("option").length).toEqual(2); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.MoneyWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("Moneyidget", () => { 8 | it("should render a form with a number input and an addon", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "money" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=number]").length).toEqual(1); 28 | expect(wrapper.find(".input-group-addon").length).toEqual(1); 29 | }); 30 | 31 | it("required gives the input the required attribute", () => { 32 | const schema = { 33 | title: "A schema", 34 | properties: { 35 | field: { 36 | type: "string", 37 | widget: "money" 38 | } 39 | }, 40 | required: ["field"] 41 | }; 42 | 43 | const Component = ( 44 | 45 | 46 | 47 | ); 48 | 49 | const wrapper = render(Component); 50 | 51 | expect(wrapper.find("input[required]").length).toEqual(1); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /src/__tests__/themes.bootstrap3.PercentWidget.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import React from "react"; 3 | import Liform from "../"; 4 | import { FormFrame } from "./test-utils"; 5 | import { shallow, mount, render } from "enzyme"; 6 | 7 | describe("PercentWidget", () => { 8 | it("should render a form with a number input and an addon", () => { 9 | const schema = { 10 | title: "A schema", 11 | properties: { 12 | field: { 13 | type: "string", 14 | widget: "percent" 15 | } 16 | } 17 | }; 18 | 19 | const Component = ( 20 | 21 | 22 | 23 | ); 24 | 25 | const wrapper = render(Component); 26 | 27 | expect(wrapper.find("input[type=number]").length).toEqual(1); 28 | expect(wrapper.find(".input-group-addon").length).toEqual(1); 29 | }); 30 | it("required gives the input the required attribute", () => { 31 | const schema = { 32 | title: "A schema", 33 | properties: { 34 | field: { 35 | type: "string", 36 | widget: "percent" 37 | } 38 | }, 39 | required: ["field"] 40 | }; 41 | 42 | const Component = ( 43 | 44 | 45 | 46 | ); 47 | 48 | const wrapper = render(Component); 49 | 50 | expect(wrapper.find("input[required]").length).toEqual(1); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/renderField.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import deepmerge from "deepmerge"; 3 | 4 | const guessWidget = (fieldSchema, theme) => { 5 | if (fieldSchema.widget) { 6 | return fieldSchema.widget; 7 | } else if (fieldSchema.hasOwnProperty("enum")) { 8 | return "choice"; 9 | } else if (fieldSchema.hasOwnProperty("oneOf")) { 10 | return "oneOf"; 11 | } else if (theme[fieldSchema.format]) { 12 | return fieldSchema.format; 13 | } 14 | return fieldSchema.type || "object"; 15 | }; 16 | 17 | const renderField = ( 18 | fieldSchema, 19 | fieldName, 20 | theme, 21 | prefix = "", 22 | context = {}, 23 | required = false 24 | ) => { 25 | if (fieldSchema.hasOwnProperty("allOf")) { 26 | fieldSchema = { ...fieldSchema, ...deepmerge.all(fieldSchema.allOf) }; 27 | delete fieldSchema.allOf; 28 | } 29 | 30 | const widget = guessWidget(fieldSchema, theme); 31 | 32 | if (!theme[widget]) { 33 | throw new Error("liform: " + widget + " is not defined in the theme"); 34 | } 35 | 36 | const newFieldName = prefix ? prefix + fieldName : fieldName; 37 | 38 | return React.createElement(theme[widget], { 39 | key: fieldName, 40 | fieldName: widget === "oneOf" ? fieldName : newFieldName, 41 | label: 42 | fieldSchema.showLabel === false ? "" : fieldSchema.title || fieldName, 43 | required: required, 44 | schema: fieldSchema, 45 | theme, 46 | context, 47 | prefix 48 | }); 49 | }; 50 | 51 | export default renderField; 52 | -------------------------------------------------------------------------------- /src/themes/index.js: -------------------------------------------------------------------------------- 1 | import StringWidget from "./StringWidget"; 2 | import TextareaWidget from "./TextareaWidget"; 3 | import EmailWidget from "./EmailWidget"; 4 | import NumberWidget from "./NumberWidget"; 5 | import MoneyWidget from "./MoneyWidget"; 6 | import PercentWidget from "./PercentWidget"; 7 | import ArrayWidget from "./ArrayWidget"; 8 | import CheckboxWidget from "./CheckboxWidget"; 9 | import ObjectWidget from "./ObjectWidget"; 10 | import PasswordWidget from "./PasswordWidget"; 11 | import SearchWidget from "./SearchWidget"; 12 | import UrlWidget from "./UrlWidget"; 13 | import ColorWidget from "./ColorWidget"; 14 | import ChoiceWidget from "./ChoiceWidget"; 15 | import OneOfChoiceWidget from "./oneOfChoiceWidget"; 16 | import DateWidget from "./DateWidget"; 17 | import TimeWidget from "./TimeWidget"; 18 | import DateTimeWidget from "./DateTimeWidget"; 19 | import CompatibleDateWidget from "./CompatibleDateWidget"; 20 | 21 | export default { 22 | object: ObjectWidget, 23 | string: StringWidget, 24 | textarea: TextareaWidget, 25 | email: EmailWidget, 26 | integer: NumberWidget, 27 | number: NumberWidget, 28 | money: MoneyWidget, 29 | percent: PercentWidget, 30 | array: ArrayWidget, 31 | boolean: CheckboxWidget, 32 | password: PasswordWidget, 33 | search: SearchWidget, 34 | url: UrlWidget, 35 | color: ColorWidget, 36 | choice: ChoiceWidget, 37 | date: DateWidget, 38 | datetime: DateTimeWidget, 39 | time: TimeWidget, 40 | OneOfChoiceWidget: OneOfChoiceWidget, 41 | "compatible-date": CompatibleDateWidget 42 | }; 43 | -------------------------------------------------------------------------------- /docs/pages/examples/combining-schemas/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import { createStore, combineReducers } from 'redux' 4 | import { reducer as formReducer } from 'redux-form' 5 | import { Provider } from 'react-redux' 6 | import Liform from '../../../../src/' 7 | 8 | 9 | const Demo = () => { 10 | const reducer = combineReducers({ form: formReducer }) 11 | const store = createStore(reducer) 12 | const schema = { 13 | "description" : "schema validating people and vehicles", 14 | "type" : "object", 15 | "oneOf" : [{ 16 | "properties" : { 17 | "firstName" : { 18 | "type" : "string" 19 | }, 20 | "lastName" : { 21 | "type" : "string" 22 | }, 23 | "sport" : { 24 | "type" : "string" 25 | } 26 | }, 27 | "required" : ["firstName"] 28 | }, { 29 | "properties" : { 30 | "vehicle" : { 31 | "type" : "string" 32 | }, 33 | "price" : { 34 | "type" : "integer" 35 | } 36 | }, 37 | "additionalProperties":false 38 | }] 39 | } 40 | return ( 41 | 42 | {console.log(v)}}/> 43 | 44 | ) 45 | } 46 | 47 | ReactDOM.render( 48 | , 49 | document.getElementById('placeholder') 50 | ) 51 | 52 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/CheckboxWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import classNames from "classnames"; 4 | import { Field } from "redux-form"; 5 | 6 | const renderInput = field => { 7 | const className = classNames([ 8 | "form-group", 9 | { "has-error": field.meta.touched && field.meta.error } 10 | ]); 11 | return ( 12 |
13 |
14 | 23 |
24 | {field.meta.touched && 25 | field.meta.error && ( 26 | {field.meta.error} 27 | )} 28 | {field.description && ( 29 | {field.description} 30 | )} 31 |
32 | ); 33 | }; 34 | 35 | const CheckboxWidget = props => { 36 | return ( 37 | 46 | ); 47 | }; 48 | 49 | CheckboxWidget.propTypes = { 50 | schema: PropTypes.object.isRequired, 51 | fieldName: PropTypes.string, 52 | label: PropTypes.string, 53 | theme: PropTypes.object 54 | }; 55 | 56 | export default CheckboxWidget; 57 | -------------------------------------------------------------------------------- /src/__tests__/renderFields.spec.js: -------------------------------------------------------------------------------- 1 | import expect from "expect"; 2 | import renderFields from "../renderFields"; 3 | import DefaultTheme from "../themes/bootstrap3"; 4 | 5 | describe("renderFields", () => { 6 | const schema = { 7 | title: "A schema", 8 | properties: { 9 | name: { 10 | type: "string", 11 | title: "A name" 12 | } 13 | } 14 | }; 15 | 16 | const schemaWrong = { 17 | title: "A schema", 18 | properties: { 19 | name: { 20 | type: "asdf" 21 | } 22 | } 23 | }; 24 | 25 | it("raises exception if type is not defined", () => { 26 | expect(function() { 27 | renderFields(schemaWrong, DefaultTheme); 28 | }).toThrow(/liform:/); 29 | }); 30 | 31 | it("creates element with a label", () => { 32 | const elems = renderFields(schema, DefaultTheme); 33 | expect(elems[0].props).toHaveProperty("label"); 34 | }); 35 | it("respects order of elements", () => { 36 | const schemaOrder = { 37 | title: "A schema", 38 | properties: { 39 | familyName: { 40 | type: "string", 41 | title: "A surname", 42 | propertyOrder: 2 43 | }, 44 | name: { 45 | type: "string", 46 | title: "A name", 47 | propertyOrder: 1 48 | }, 49 | another: { 50 | type: "string", 51 | title: "Another", 52 | propertyOrder: 3 53 | } 54 | } 55 | }; 56 | const elems = renderFields(schemaOrder, DefaultTheme); 57 | expect(elems[0].props.label).toBe("A name"); 58 | expect(elems[1].props.label).toBe("A surname"); 59 | expect(elems[2].props.label).toBe("Another"); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /src/themes/bootstrap3/TextareaWidget.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import PropTypes from "prop-types"; 3 | import classNames from "classnames"; 4 | import { Field } from "redux-form"; 5 | 6 | const renderInput = field => { 7 | const className = classNames([ 8 | "form-group", 9 | { "has-error": field.meta.touched && field.meta.error } 10 | ]); 11 | return ( 12 |
13 | 16 |