├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── dist └── react-selectize.js ├── examples └── sightseeings.html ├── package.json └── src └── react-selectize.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | bower_components/ 3 | react-0.10.0/ 4 | **/.* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Igor Ovsyannikov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | React wrapper for [Selectize ](http://brianreavis.github.io/selectize.js/) 2 | =============== 3 | 4 | ##NO LONGER MAINTAINED 5 | 6 | **The package was made as temporary solution and will be no longer maintained. 7 | Although you can still use it i would strongly recommend to switch for mature React UI library [material-ui](https://github.com/callemall/material-ui) or alike.** 8 | 9 | I have made simple React wrapper around selectize primarily for myself. 10 | But if you find it helpful, fill free to use. 11 | 12 | And of course fill free to add merge requests or register issues. 13 | I will try to handle it as soon as i can. 14 | 15 | 16 | #Changelog 17 | - 07.04.2014 Fixed issue when selectize`s dropdown was reopenning after onChange event 18 | - 10.04.2014 Added ability to pass classes through props ('control-group' class removed) 19 | - 09.04.2015 Update for React v0.13. Incoroprate some PR. Mark as Obsolete. 20 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-selectize", 3 | "version": "0.1.0", 4 | "authors": [ 5 | "igor ovsyannikov " 6 | ], 7 | "description": "React wrapper around Selectize", 8 | "main": "dist/react-selectize.js", 9 | "moduleType": [ 10 | "globals" 11 | ], 12 | "keywords": [ 13 | "selectize", 14 | "react", 15 | "javascript", 16 | "library" 17 | ], 18 | "license": "MIT", 19 | "homepage": "https://github.com/ggarek/react-selectize", 20 | "ignore": [ 21 | "**/.*", 22 | "node_modules", 23 | "bower_components", 24 | "test", 25 | "tests" 26 | ], 27 | "dependencies": { 28 | "selectize": "~0.9.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dist/react-selectize.js: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | 3 | /* React selectize wrapper */ 4 | var ReactSelectize = React.createClass({displayName: "ReactSelectize", 5 | 6 | getDefaultProps: function () { 7 | return { 8 | valueField: "id", 9 | labelField: "name", 10 | searchField: "name", 11 | sortField: "id", 12 | create: false, 13 | items: [] 14 | }; 15 | }, 16 | 17 | isMultiple: function (props) { 18 | // Selectize becomes 'multiple' when 'maxItems' is passed via settings 19 | return props.multiple || props.maxItems != undefined; 20 | }, 21 | 22 | buildOptions: function () { 23 | var o = {}; 24 | 25 | o.valueField = this.props.valueField; 26 | o.labelField = this.props.labelField; 27 | o.searchField = this.props.searchField; 28 | o.sortField = this.props.sortField; 29 | if(this.isMultiple(this.props)){ 30 | o.maxItems = this.props.maxItems || null; 31 | } 32 | o.options = this.props.items; 33 | o.create = this.props.create; 34 | 35 | return o; 36 | }, 37 | 38 | getSelectizeControl: function () { 39 | var selectId = "#" + this.props.selectId, 40 | $select = $(selectId), 41 | selectControl = $select[0] && $select[0].selectize; 42 | 43 | return selectControl; 44 | }, 45 | 46 | handleChange: function (e) { 47 | 48 | // IF Selectize is not multiple 49 | if(!this.isMultiple(this.props)){ 50 | // THEN blur it before calling onChange to prevent dropdown reopening 51 | this.getSelectizeControl().blur(); 52 | } 53 | 54 | if(this.props.onChange){ 55 | this.props.onChange(e); 56 | } 57 | }, 58 | 59 | rebuildSelectize: function () { 60 | var $select = null, 61 | selectControl = this.getSelectizeControl(), 62 | items = this.props.items; 63 | 64 | if(selectControl) { 65 | // rebuild 66 | selectControl.off(); 67 | selectControl.clearOptions(); 68 | selectControl.load(function (cb) { cb(items) }); 69 | } else { 70 | // build new 71 | $select = $("#" + this.props.selectId).selectize(this.buildOptions()); 72 | selectControl = $select[0].selectize; 73 | } 74 | 75 | selectControl.setValue(this.props.value); 76 | 77 | if(this.props.onChange){ 78 | selectControl.on('change', this.handleChange); 79 | } 80 | }, 81 | 82 | componentDidMount: function () { 83 | this.rebuildSelectize(); 84 | }, 85 | 86 | componentDidUpdate: function () { 87 | this.rebuildSelectize(); 88 | }, 89 | 90 | render: function () { 91 | var classes = this.props.classes; 92 | return React.createElement("div", {className: classes && classes.length > 0 ? classes.join(' ') : ''}, 93 | React.createElement("label", {htmlFor: this.props.selectId}, this.props.label), 94 | React.createElement("select", {id: this.props.selectId, placeholder: this.props.placeholder}) 95 | ) 96 | } 97 | }); 98 | -------------------------------------------------------------------------------- /examples/sightseeings.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 90 | 91 | 92 | 161 | 162 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-selectize", 3 | "version": "0.1.0", 4 | "description": "React wrapper around Selectize", 5 | "main": "dist/react-selectize.js", 6 | "directories": { 7 | "example": "examples" 8 | }, 9 | "scripts": { 10 | "build": "rm -r dist/** && jsx src/ dist/", 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/ggarek/react-selectize.git" 16 | }, 17 | "keywords": [ 18 | "selectize", 19 | "react" 20 | ], 21 | "author": "igor ovsyannikov ", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/ggarek/react-selectize/issues" 25 | }, 26 | "homepage": "https://github.com/ggarek/react-selectize", 27 | "devDependencies": { 28 | "react": "^0.13.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/react-selectize.js: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | 3 | /* React selectize wrapper */ 4 | var ReactSelectize = React.createClass({ 5 | 6 | getDefaultProps: function () { 7 | return { 8 | valueField: "id", 9 | labelField: "name", 10 | searchField: "name", 11 | sortField: "id", 12 | create: false, 13 | items: [] 14 | }; 15 | }, 16 | 17 | isMultiple: function (props) { 18 | // Selectize becomes 'multiple' when 'maxItems' is passed via settings 19 | return props.multiple || props.maxItems != undefined; 20 | }, 21 | 22 | buildOptions: function () { 23 | var o = {}; 24 | 25 | o.valueField = this.props.valueField; 26 | o.labelField = this.props.labelField; 27 | o.searchField = this.props.searchField; 28 | o.sortField = this.props.sortField; 29 | if(this.isMultiple(this.props)){ 30 | o.maxItems = this.props.maxItems || null; 31 | } 32 | o.options = this.props.items; 33 | o.create = this.props.create; 34 | 35 | return o; 36 | }, 37 | 38 | getSelectizeControl: function () { 39 | var selectId = "#" + this.props.selectId, 40 | $select = $(selectId), 41 | selectControl = $select[0] && $select[0].selectize; 42 | 43 | return selectControl; 44 | }, 45 | 46 | handleChange: function (e) { 47 | 48 | // IF Selectize is not multiple 49 | if(!this.isMultiple(this.props)){ 50 | // THEN blur it before calling onChange to prevent dropdown reopening 51 | this.getSelectizeControl().blur(); 52 | } 53 | 54 | if(this.props.onChange){ 55 | this.props.onChange(e); 56 | } 57 | }, 58 | 59 | rebuildSelectize: function () { 60 | var $select = null, 61 | selectControl = this.getSelectizeControl(), 62 | items = this.props.items; 63 | 64 | if(selectControl) { 65 | // rebuild 66 | selectControl.off(); 67 | selectControl.clearOptions(); 68 | selectControl.load(function (cb) { cb(items) }); 69 | } else { 70 | // build new 71 | $select = $("#" + this.props.selectId).selectize(this.buildOptions()); 72 | selectControl = $select[0].selectize; 73 | } 74 | 75 | selectControl.setValue(this.props.value); 76 | 77 | if(this.props.onChange){ 78 | selectControl.on('change', this.handleChange); 79 | } 80 | }, 81 | 82 | componentDidMount: function () { 83 | this.rebuildSelectize(); 84 | }, 85 | 86 | componentDidUpdate: function () { 87 | this.rebuildSelectize(); 88 | }, 89 | 90 | render: function () { 91 | var classes = this.props.classes; 92 | return
0 ? classes.join(' ') : ''}> 93 | 94 | 95 |
96 | } 97 | }); 98 | --------------------------------------------------------------------------------