react-input-message
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -55,3 +55,3 @@ var _inherits = function (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) subClass.__proto__ = superClass; }; | ||
MessageListener.prototype._getValidationState = function _getValidationState() { | ||
var messages = this.getContext().messages(this.props.for || this.props.group); | ||
var messages = this.getContext().messages(this.props.for, this.props.group); | ||
@@ -58,0 +58,0 @@ return { |
@@ -19,2 +19,6 @@ "use strict"; | ||
var has = function (obj, key) { | ||
return obj && ({}).hasOwnProperty.call(obj, key); | ||
}; | ||
module.exports = (function (_React$Component) { | ||
@@ -28,4 +32,4 @@ function ValidationContainer(props, context) { | ||
this._groups = window.Map ? new Map() : Object.create(null); | ||
this._fields = window.Map ? new Map() : Object.create(null); | ||
this._groups = Object.create(null); | ||
this._fields = Object.create(null); | ||
@@ -115,3 +119,3 @@ this.state = { | ||
if (!(!group || !group.length)) [].concat(group).forEach(function (grp) { | ||
if (!_this._groups.hasOwnProperty(grp)) return _this._groups[grp] = [name]; | ||
if (!has(_this._groups, grp)) return _this._groups[grp] = [name]; | ||
@@ -135,3 +139,3 @@ if (_this._groups[grp].indexOf(name) === -1) _this._groups[grp].push(name); | ||
for (var key in this._groups) if (this._groups.hasOwnProperty(key)) remove(name, key); | ||
for (var key in this._groups) if (has(this._groups, key)) remove(name, key); | ||
@@ -163,7 +167,11 @@ this._fields[name] = false; | ||
ValidationContainer.prototype._messages = function _messages(names) { | ||
ValidationContainer.prototype._messages = function _messages(names, groups) { | ||
var _this = this; | ||
if (!names || !names.length) return _extends({}, this.props.messages); | ||
if (!names || !names.length) { | ||
if (!groups || !groups.length) return _extends({}, this.props.messages); | ||
names = this.fields(groups); | ||
} | ||
return [].concat(names).reduce(function (o, name) { | ||
@@ -170,0 +178,0 @@ if (_this.props.messages[name]) o[name] = _this.props.messages[name]; |
{ | ||
"name": "react-input-message", | ||
"description": "unopinionated form input annotation", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/jquense/react-input-message.git" |
@@ -8,9 +8,51 @@ var React = require('react/addons') | ||
var findTag = utils.findRenderedDOMComponentWithTag | ||
, findClass = utils.findRenderedDOMComponentWithClass | ||
, findAllTag = utils.scryRenderedDOMComponentsWithTag | ||
, findAllClass = utils.scryRenderedDOMComponentsWithClass | ||
, findType = utils.findRenderedComponentWithType | ||
, findAllType = utils.scryRenderedComponentsWithType | ||
, trigger = utils.Simulate | ||
describe('connect to container HoC', ()=>{ | ||
describe('Message', ()=>{ | ||
it('should use the prop Component', function(){ | ||
var inst = utils.renderIntoDocument( | ||
<MessageContainer messages={{ fieldA: 'hi', fieldB: 'good day' }} > | ||
<div> | ||
<Message for='fieldA' className='msg' component='p'/> | ||
</div> | ||
</MessageContainer>) | ||
var messages = findTag(inst, 'p'); | ||
}) | ||
it('should allow empty `for`', function(){ | ||
var inst = utils.renderIntoDocument( | ||
<MessageContainer messages={{ fieldA: 'hi', fieldB: 'good day' }} > | ||
<div> | ||
<Message className='msg'/> | ||
</div> | ||
</MessageContainer>) | ||
var messages = findType(inst, Message._Message); | ||
messages.props.messages.should.eql({ fieldA: 'hi', fieldB: 'good day' }) | ||
}) | ||
it('should allow group summaries', function(){ | ||
var inst = utils.renderIntoDocument( | ||
<MessageContainer messages={{ fieldA: 'hi', fieldB: 'good day' }} > | ||
<div> | ||
<MessageTrigger for='fieldA' group='test'> | ||
<input/> | ||
</MessageTrigger> | ||
<Message group='test' className='msg'/> | ||
</div> | ||
</MessageContainer>) | ||
var messages = findType(inst, Message._Message); | ||
messages.props.messages.should.eql({ fieldA: 'hi' }) | ||
}) | ||
}) |
@@ -9,3 +9,2 @@ 'use strict'; | ||
var findTag = utils.findRenderedDOMComponentWithTag | ||
@@ -12,0 +11,0 @@ , findClass = utils.findRenderedDOMComponentWithClass |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235914
5268