Sha256: b6697ca068148b25ba8e6b8e0e740a0936d5a24dd253123ad1368d3368f6bdf0

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

import React from 'react';

import PropTypes from 'prop-types';

Hippo.Components.Form.InputFieldMixin = {

    mixins: [
        Hippo.Components.Form.FieldMixin
    ],

    propTypes: {
        onlyNumeric:  PropTypes.bool,
        selctOnFocus: PropTypes.bool,
        onEnter: PropTypes.func
    },

    focus() {
        return (
            _.dom(this, 'input').el.focus()
        );
    },

    getDefaultProps() {
        return (
            {type: 'text'}
        );
    },

    handleKeyDown(ev) {
        if (ev.key === 'Enter') { return this.props.onEnter(); }
    },

    selectOnFocus(ev) {
        return (
            ev.target.select()
        );
    },

    onFieldBlur() {
        this.onFieldInteraction();
        return (
            __guardMethod__(this.props, 'onBlur', o => o.onBlur())
        );
    },

    renderEdit(props) {
        props = _.extend(props, {
            ref: 'input',
            name: this.props.name,
            value: this.fieldMixinGetValue()
        });

        const handlers = { onBlur: this.onFieldBlur };

        if (this.props.onEnter) {         handlers.onKeyDown = this.handleKeyDown; }
        if (this.props.selectOnFocus) {   handlers.onFocus   = this.selectOnFocus; }

        props = Hippo.u.cleanBsSizes(props);

        return (

            this.renderInputField(props, handlers)

        );
    }
};

function __guardMethod__(obj, methodName, transform) {
  if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') {
    return (
        transform(obj, methodName)
    );
  } else {
    return (
        undefined
    );
  }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hippo-fw-0.9.5 client/hippo/components/shared/InputFieldMixin.jsx
hippo-fw-0.9.4 client/hippo/components/shared/InputFieldMixin.jsx
hippo-fw-0.9.3 client/hippo/components/shared/InputFieldMixin.jsx
hippo-fw-0.9.2 client/hippo/components/shared/InputFieldMixin.jsx
hippo-fw-0.9.1 client/hippo/components/shared/InputFieldMixin.jsx