Home Reference Source

application/metaproperties/printonly-meta-property.js

import React from 'react';
import TextField from 'material-ui/TextField';
import shallowCompare from 'react-addons-shallow-compare';

class PrintonlyMetaProperty extends React.Component {
    constructor(props) {
        super(props);
        this.displayName = 'PrintonlyMetaProperty';
    }

    shouldComponentUpdate(nextProps, nextState) {
        if (nextProps.value != this.props.value) {
            return true;
        }
        if (nextProps.disabled != this.props.disabled) {
            return true;
        }
        return false;
    }

    rando() {
        const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

        let str = [];
        for (let i=0; i<5; i++) {
            str.push(chars.charAt(Math.floor(Math.random() * chars.length)));
        }

        return str.join('');
    }

    render() {
        const name = this.props.name ? this.props.name : 'hiddenfield_' + this.rando();
        return (
            <input type="hidden" name={name} {...this.props}/>
        );
    }
}

export default PrintonlyMetaProperty;