UNPKG

ldx-widgets

Version:

widgets

81 lines (72 loc) 2.41 kB
(function() { var AddValidationContext, Flux, React, ReactDOM, _, div; React = require('react'); ReactDOM = require('react-dom'); div = React.DOM.div; Flux = require('delorean').Flux; _ = require('lodash'); AddValidationContext = React.createClass({ mixins: [Flux.mixins.storeListener], watchStores: ['validation'], childContextTypes: { clearValidationError: React.PropTypes.func, addValidationError: React.PropTypes.func, getValidationStatus: React.PropTypes.func, toggleValidationError: React.PropTypes.func }, getChildContext: function() { return { clearValidationError: this.clearValidationError, addValidationError: this.addValidationError, getValidationStatus: this.getValidationStatus, toggleValidationError: this.toggleValidationError }; }, componentWillMount: function() { var ref; return this.ref = ((ref = this.props.childProps) != null ? ref.ref : void 0) || 'input'; }, render: function() { var childProps, children, factory, props, ref; ref = this.props, factory = ref.factory, childProps = ref.childProps, children = ref.children; props = _.assign({}, childProps, { ref: this.ref }); return div({ key: 'wrapper' }, children || factory(props)); }, getInput: function() { return this.refs[this.ref]; }, getInputEl: function() { return ReactDOM.findDOMNode(this.refs[this.ref]); }, clearValidationError: function(inputId) { return this.trigger('clearValidationError', inputId); }, addValidationError: function(anchor, error, groupId) { return this.trigger('addValidationError', { anchor: anchor, error: error, groupId: groupId }); }, getValidationStatus: function(inputId) { var errors, forceShowAllErrors, ref; ref = this.getStore('validation'), errors = ref.errors, forceShowAllErrors = ref.forceShowAllErrors; return { error: errors[inputId], forceShowAllErrors: forceShowAllErrors }; }, toggleValidationError: function(inputId, status) { return this.trigger('toggleError', { groupId: this.inputId, status: status, isMouseOver: true }); } }); module.exports = React.createFactory(AddValidationContext); }).call(this);