8000 How to access field in custom widget? · Issue #95 · insin/newforms · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How to access field in custom widget? #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kevzettler opened this issue May 13, 2015 · 1 comment
Open

How to access field in custom widget? #95

kevzettler opened this issue May 13, 2015 · 1 comment

Comments

@kevzettler
Copy link

I'm building a custom widget that I want to render differently depending on if the field data is valid or not.
How do I check the valid state from a widget?

var React = require('react'),
    Base = require('newforms').TextInput;

var UnderlineInput = Base.extend({
    constructor: function UnderlineInput(kwargs) {
        if(!(this instanceof UnderlineInput)) {
            return new UnderlineInput(kwargs);
        }

        Base.call(this, kwargs);
    }
});

UnderlineInput.prototype.render = function(name, value, kwargs) {
    var finalAttrs = this.buildAttrs(kwargs.attrs, {
        name: name
    });

    var valueAttr = kwargs.controlled ? 'value' : 'defaultValue';
    finalAttrs[valueAttr] = value;

    return (
        <div className="underline-input">
            <label>$<input {...finalAttrs} /></label>
        </div>
    );
};

module.exports = UnderlineInput;
@marr
Copy link
marr commented May 14, 2015

Untested, but have you tried the :valid and :invalid pseudoselectors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0