Giter VIP home page Giter VIP logo

Comments (14)

syllog1sm avatar syllog1sm commented on April 27, 2024

Hmm. That's a good start, but there's a fair bit going on in the Boostrap component. It's confusing though, because the docs are a bit scattered (as usual):

http://getbootstrap.com/css/#forms
http://getbootstrap.com/components/#input-groups

Here's how my current Input component works. It doesn't use all of the functionality either.

            <Form callback={this.submit}>
                <Input name="email" type="email" placeholder="Email" required={true}/>
                <Input name="password" type="password" placeholder="Password"/>
                <Input name="password" type="password" placeholder="Re-enter Password"/>
                <Button bsStyle="success" bsSize="large">
                    Submit
                </Button>
                <Button bsStyle="danger" bsSize="large">
                    Cancel
                </Button>
            </Form>

Here's my implementation of Input. It does some validation; I'm not sure if this is a great idea.

var Input = React.createClass({
    propTypes: {
        name: React.PropTypes.string.isRequired,
        type: React.PropTypes.oneOf(INPUT_TYPES).isRequired,
        placeholder: React.PropTypes.string,
        label: React.PropTypes.string,
        required: React.PropTypes.bool,
        oneOf: React.PropTypes.array,
        minLength: React.PropTypes.int
    },

    getInitialState: function() { return {}; },

    getValue: function() {
        return this.refs.input.getDOMNode().value;
    },

    renderInput: function(){
        var className = "form-control input-md";
        return <input type={this.props.type} className={className}
            placeholder={this.props.placeholder} ref="input"/>;
    },

    renderLabel: function(){
        return this.props.label ? <label>{this.props.label}</label> : undefined;
    },

    render: function(){
        var className = "form-group";
        if (this.state.error)
            className += ' has-error';
        return this.transferPropsTo(
            <div className={className} onBlur={this.onBlur} onFocus={this.onFocus}>
                {this.renderInput()}
                {this.renderLabel()}
            </div>
        );
    },

    onBlur: function(e){
        var value = this.getValue();
        var error;
        if (this.props.required && !value)
            error = 'required';
        else if (this.props.oneOf && !(value in this.props.oneOf))
            error = 'oneOf';
        else if (this.props.minLength && value.length < this.props.minLength)
            error = 'minLength';
        this.setState({error: error});
    },

    onFocus: function(e) {
        this.setState({error: false});
        e.stopPropagation();
    }
});

from react-bootstrap.

stevoland avatar stevoland commented on April 27, 2024

I'd like to leave validation out of the component at least for now. Just add the relevant error/warning class from some prop like bsStyle in my example. What other functionality can you see missing from my initial example?

from react-bootstrap.

syllog1sm avatar syllog1sm commented on April 27, 2024

I missed that "before" and "after" would do the input-group parts, so that's covered.

Where does placeholder text go?

from react-bootstrap.

stevoland avatar stevoland commented on April 27, 2024

oh, yeah, forgot placeholder - I'll add that.

On Tue, Feb 11, 2014 at 3:03 PM, syllog1sm [email protected] wrote:

I missed that "before" and "after" would do the input-group parts, so
that's covered.

Where does placeholder text go?

Reply to this email directly or view it on GitHubhttps://github.com//issues/20#issuecomment-34762245
.

from react-bootstrap.

velsa avatar velsa commented on April 27, 2024

What would be really cool is to have Input with optional autocompletion
Thanks !

from react-bootstrap.

stevoland avatar stevoland commented on April 27, 2024

That would be great. Id like a pure React Selectize https://github.com/brianreavis/selectize.js . It's not going to happen in this project I'm afraid.

from react-bootstrap.

velsa avatar velsa commented on April 27, 2024

Answering my own comment: https://github.com/chenglou/react-chosen

For those looking )

from react-bootstrap.

liamcmitchell avatar liamcmitchell commented on April 27, 2024

Is there any work in progress? I may have some time to spend on it.

I agree that validation should stay out for now.

from react-bootstrap.

stevoland avatar stevoland commented on April 27, 2024

That would be fantastic! I don't think it's been started.@pieterv ?

from react-bootstrap.

pieterv avatar pieterv commented on April 27, 2024

@liamcmitchell sounds good! I haven't made any progress on this.

For validation it would be nice if we can make sure HTML5 validation properties can still be set on the input, required being the main one.

from react-bootstrap.

liamcmitchell avatar liamcmitchell commented on April 27, 2024

Work in progress here: #89

from react-bootstrap.

PetrSnobelt avatar PetrSnobelt commented on April 27, 2024

Just note that there is wrapper around selectize.js
https://github.com/ggarek/react-selectize

from react-bootstrap.

mtscout6 avatar mtscout6 commented on April 27, 2024

@PetrSnobelt Did you so that library's announcement that it is no longer maintained? What are you looking for?

from react-bootstrap.

PetrSnobelt avatar PetrSnobelt commented on April 27, 2024

I know, but it is only wrapper...
I'm looking for great autocomplete/suggestion component (like selectize) for react-bootstrap

from react-bootstrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.