UNPKG

ldx-widgets

Version:

widgets

75 lines (66 loc) 2.17 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 }; }, render: function() { var childProps, factory, props, ref; ref = this.props, factory = ref.factory, childProps = ref.childProps; props = _.assign({}, childProps, { ref: 'input' }); return div({}, factory(props)); }, getInput: function() { return this.refs.input; }, getInputEl: function() { return ReactDOM.findDOMNode(this.refs.input); }, 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);