-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add onBlur event #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add onBlur event #444
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0be655f
added onBlur event
eeinowski a08b95f
added on blur event
eeinowski aad1536
removed debugger expression
eeinowski 409341b
removed list from gitignore and built a dist for use with npm
eeinowski d1fc419
added lib to git repo
eeinowski 353a64f
fixed error in onblur testing
megantfanning 1719a4e
added onBlur check for arrayField_test
megantfanning 7a53913
added onblur test for boolean field
megantfanning a8a0495
added onBlur for numberfield
megantfanning b1df603
onBlur testing added for array,number,object,string fields adn uischema
megantfanning 73567cc
added if statement to onblur to ensure it's only called if there is a…
megantfanning aa7c3cd
fixed arrayfield test
megantfanning b6334be
Merge pull request #1 from eeinowski/megansOnBlurEvent
megantfanning 8f8936a
addded if block around onBlur event in checkBox widget
megantfanning 30b148d
added on blur test for datetimefield
megantfanning bea4062
changed expect to match chai styling
megantfanning d469072
fixed spy syntax
megantfanning c75af52
fixed error in date time widget test
megantfanning 10c5830
added onblur testing for widgets in stringfield test
megantfanning f66aa11
added password and textArea widget testing to string tests for onBlur
megantfanning 827d6f1
added widget testing for radio, range, select in numberfield test
megantfanning 4266379
linting project complete
megantfanning 4e01bd6
added information about onBlur to Readme
megantfanning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| npm-debug.log | ||
| node_modules | ||
| build | ||
| dist | ||
| lib | ||
|
|
||
| .idea | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| "use strict"; | ||
|
|
||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = ErrorList; | ||
|
|
||
| var _react = require("react"); | ||
|
|
||
| var _react2 = _interopRequireDefault(_react); | ||
|
|
||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
|
||
| function ErrorList(_ref) { | ||
| var errors = _ref.errors; | ||
|
|
||
| return _react2.default.createElement( | ||
| "div", | ||
| { className: "panel panel-danger errors" }, | ||
| _react2.default.createElement( | ||
| "div", | ||
| { className: "panel-heading" }, | ||
| _react2.default.createElement( | ||
| "h3", | ||
| { className: "panel-title" }, | ||
| "Errors" | ||
| ) | ||
| ), | ||
| _react2.default.createElement( | ||
| "ul", | ||
| { className: "list-group" }, | ||
| errors.map(function (error, i) { | ||
| return _react2.default.createElement( | ||
| "li", | ||
| { key: i, className: "list-group-item text-danger" }, | ||
| error.stack | ||
| ); | ||
| }) | ||
| ) | ||
| ); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for lib files, they're generated locally then published to npm, and should therefore not be versioned in this repository. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,286 @@ | ||
| 'use strict'; | ||
|
|
||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
|
|
||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
|
|
||
| var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
|
||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
|
|
||
| var _react = require('react'); | ||
|
|
||
| var _react2 = _interopRequireDefault(_react); | ||
|
|
||
| var _ErrorList = require('./ErrorList'); | ||
|
|
||
| var _ErrorList2 = _interopRequireDefault(_ErrorList); | ||
|
|
||
| var _utils = require('../utils'); | ||
|
|
||
| var _validate = require('../validate'); | ||
|
|
||
| var _validate2 = _interopRequireDefault(_validate); | ||
|
|
||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
|
||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
|
||
| function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
|
|
||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
|
||
| var Form = function (_Component) { | ||
| _inherits(Form, _Component); | ||
|
|
||
| function Form(props) { | ||
| _classCallCheck(this, Form); | ||
|
|
||
| var _this = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this, props)); | ||
|
|
||
| _this.onChange = function (formData) { | ||
| var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { validate: false }; | ||
|
|
||
| var mustValidate = !_this.props.noValidate && (_this.props.liveValidate || options.validate); | ||
| var state = { status: "editing", formData: formData }; | ||
| if (mustValidate) { | ||
| var _this$validate = _this.validate(formData), | ||
| errors = _this$validate.errors, | ||
| errorSchema = _this$validate.errorSchema; | ||
|
|
||
| state = _extends({}, state, { errors: errors, errorSchema: errorSchema }); | ||
| } | ||
| (0, _utils.setState)(_this, state, function () { | ||
| if (_this.props.onChange) { | ||
| _this.props.onChange(_this.state); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| _this.onBlur = function () { | ||
| if (_this.props.onBlur) { | ||
| _this.props.onBlur(_this.state); | ||
| } | ||
| }; | ||
|
|
||
| _this.onSubmit = function (event) { | ||
| event.preventDefault(); | ||
| _this.setState({ status: "submitted" }); | ||
|
|
||
| if (!_this.props.noValidate) { | ||
| var _ret = function () { | ||
| var _this$validate2 = _this.validate(_this.state.formData), | ||
| errors = _this$validate2.errors, | ||
| errorSchema = _this$validate2.errorSchema; | ||
|
|
||
| if (Object.keys(errors).length > 0) { | ||
| (0, _utils.setState)(_this, { errors: errors, errorSchema: errorSchema }, function () { | ||
| if (_this.props.onError) { | ||
| _this.props.onError(errors); | ||
| } else { | ||
| console.error("Form validation failed", errors); | ||
| } | ||
| }); | ||
| return { | ||
| v: void 0 | ||
| }; | ||
| } | ||
| }(); | ||
|
|
||
| if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
| } | ||
|
|
||
| if (_this.props.onSubmit) { | ||
| _this.props.onSubmit(_this.state); | ||
| } | ||
| _this.setState({ status: "initial", errors: [], errorSchema: {} }); | ||
| }; | ||
|
|
||
| _this.state = _this.getStateFromProps(props); | ||
| return _this; | ||
| } | ||
|
|
||
| _createClass(Form, [{ | ||
| key: 'componentWillReceiveProps', | ||
| value: function componentWillReceiveProps(nextProps) { | ||
| this.setState(this.getStateFromProps(nextProps)); | ||
| } | ||
| }, { | ||
| key: 'getStateFromProps', | ||
| value: function getStateFromProps(props) { | ||
| var state = this.state || {}; | ||
| var schema = "schema" in props ? props.schema : this.props.schema; | ||
| var uiSchema = "uiSchema" in props ? props.uiSchema : this.props.uiSchema; | ||
| var edit = typeof props.formData !== "undefined"; | ||
| var liveValidate = props.liveValidate || this.props.liveValidate; | ||
| var mustValidate = edit && !props.noValidate && liveValidate; | ||
| var definitions = schema.definitions; | ||
|
|
||
| var formData = (0, _utils.getDefaultFormState)(schema, props.formData, definitions); | ||
|
|
||
| var _ref = mustValidate ? this.validate(formData, schema) : { | ||
| errors: state.errors || [], | ||
| errorSchema: state.errorSchema || {} | ||
| }, | ||
| errors = _ref.errors, | ||
| errorSchema = _ref.errorSchema; | ||
|
|
||
| var idSchema = (0, _utils.toIdSchema)(schema, uiSchema["ui:rootFieldId"], definitions); | ||
| return { | ||
| status: "initial", | ||
| schema: schema, | ||
| uiSchema: uiSchema, | ||
| idSchema: idSchema, | ||
| formData: formData, | ||
| edit: edit, | ||
| errors: errors, | ||
| errorSchema: errorSchema | ||
| }; | ||
| } | ||
| }, { | ||
| key: 'shouldComponentUpdate', | ||
| value: function shouldComponentUpdate(nextProps, nextState) { | ||
| return (0, _utils.shouldRender)(this, nextProps, nextState); | ||
| } | ||
| }, { | ||
| key: 'validate', | ||
| value: function validate(formData, schema) { | ||
| var validate = this.props.validate; | ||
|
|
||
| return (0, _validate2.default)(formData, schema || this.props.schema, validate); | ||
| } | ||
| }, { | ||
| key: 'renderErrors', | ||
| value: function renderErrors() { | ||
| var _state = this.state, | ||
| status = _state.status, | ||
| errors = _state.errors; | ||
| var showErrorList = this.props.showErrorList; | ||
|
|
||
|
|
||
| if (status !== "editing" && errors.length && showErrorList != false) { | ||
| return _react2.default.createElement(_ErrorList2.default, { errors: errors }); | ||
| } | ||
| return null; | ||
| } | ||
| }, { | ||
| key: 'getRegistry', | ||
| value: function getRegistry() { | ||
| // For BC, accept passed SchemaField and TitleField props and pass them to | ||
| // the "fields" registry one. | ||
| var _getDefaultRegistry = (0, _utils.getDefaultRegistry)(), | ||
| fields = _getDefaultRegistry.fields, | ||
| widgets = _getDefaultRegistry.widgets; | ||
|
|
||
| return { | ||
| fields: _extends({}, fields, this.props.fields), | ||
| widgets: _extends({}, widgets, this.props.widgets), | ||
| FieldTemplate: this.props.FieldTemplate, | ||
| definitions: this.props.schema.definitions || {}, | ||
| formContext: this.props.formContext || {} | ||
| }; | ||
| } | ||
| }, { | ||
| key: 'render', | ||
| value: function render() { | ||
| var _props = this.props, | ||
| children = _props.children, | ||
| safeRenderCompletion = _props.safeRenderCompletion, | ||
| id = _props.id, | ||
| className = _props.className, | ||
| name = _props.name, | ||
| method = _props.method, | ||
| target = _props.target, | ||
| action = _props.action, | ||
| autocomplete = _props.autocomplete, | ||
| enctype = _props.enctype, | ||
| acceptcharset = _props.acceptcharset, | ||
| onBlur = _props.onBlur; | ||
| var _state2 = this.state, | ||
| schema = _state2.schema, | ||
| uiSchema = _state2.uiSchema, | ||
| formData = _state2.formData, | ||
| errorSchema = _state2.errorSchema, | ||
| idSchema = _state2.idSchema; | ||
|
|
||
| var registry = this.getRegistry(); | ||
| var _SchemaField = registry.fields.SchemaField; | ||
|
|
||
| return _react2.default.createElement( | ||
| 'form', | ||
| { className: className ? className : "rjsf", | ||
| id: id, | ||
| name: name, | ||
| method: method, | ||
| target: target, | ||
| action: action, | ||
| autoComplete: autocomplete, | ||
| encType: enctype, | ||
| acceptCharset: acceptcharset, | ||
| onSubmit: this.onSubmit }, | ||
| this.renderErrors(), | ||
| _react2.default.createElement(_SchemaField, { | ||
| schema: schema, | ||
| uiSchema: uiSchema, | ||
| errorSchema: errorSchema, | ||
| idSchema: idSchema, | ||
| formData: formData, | ||
| onChange: this.onChange, | ||
| onBlur: onBlur, | ||
| registry: registry, | ||
| safeRenderCompletion: safeRenderCompletion }), | ||
| children ? children : _react2.default.createElement( | ||
| 'p', | ||
| null, | ||
| _react2.default.createElement( | ||
| 'button', | ||
| { type: 'submit', className: 'btn btn-info' }, | ||
| 'Submit' | ||
| ) | ||
| ) | ||
| ); | ||
| } | ||
| }]); | ||
|
|
||
| return Form; | ||
| }(_react.Component); | ||
|
|
||
| Form.defaultProps = { | ||
| uiSchema: {}, | ||
| noValidate: false, | ||
| liveValidate: false, | ||
| safeRenderCompletion: false | ||
| }; | ||
| exports.default = Form; | ||
|
|
||
|
|
||
| if (process.env.NODE_ENV !== "production") { | ||
| Form.propTypes = { | ||
| schema: _react.PropTypes.object.isRequired, | ||
| uiSchema: _react.PropTypes.object, | ||
| formData: _react.PropTypes.any, | ||
| widgets: _react.PropTypes.objectOf(_react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.object])), | ||
| fields: _react.PropTypes.objectOf(_react.PropTypes.func), | ||
| FieldTemplate: _react.PropTypes.func, | ||
| onChange: _react.PropTypes.func, | ||
| onBlur: _react.PropTypes.func, | ||
| onError: _react.PropTypes.func, | ||
| showErrorList: _react.PropTypes.bool, | ||
| onSubmit: _react.PropTypes.func, | ||
| id: _react.PropTypes.string, | ||
| className: _react.PropTypes.string, | ||
| name: _react.PropTypes.string, | ||
| method: _react.PropTypes.string, | ||
| target: _react.PropTypes.string, | ||
| action: _react.PropTypes.string, | ||
| autocomplete: _react.PropTypes.string, | ||
| enctype: _react.PropTypes.string, | ||
| acceptcharset: _react.PropTypes.string, | ||
| noValidate: _react.PropTypes.bool, | ||
| liveValidate: _react.PropTypes.bool, | ||
| safeRenderCompletion: _react.PropTypes.bool, | ||
| formContext: _react.PropTypes.object | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added by IntelliJ users in their own global
~/.gitignorefile. Also please readd ignore rules fordistandlib(see contextual comments above).