Skip to content
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

Add disabled for input #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Available Props
:customParams="{ token: 'dev' }"
:customHeaders="{ Authorization: 'bearer abc123' }"


:disabled="false"
:required="true"
id="custom id"
className="custom class name"
Expand Down Expand Up @@ -164,6 +164,9 @@ Delay time before do the ajax for the data
#### required (Boolean)
Required attribute for input

### disabled (Boolean)
Disabled attribute for input

#### placeholder (String)
Placeholder for input

Expand Down
2 changes: 1 addition & 1 deletion build/build.js

Large diffs are not rendered by default.

57 changes: 37 additions & 20 deletions dist/vue2-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ if (false) {(function () {
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
var _props$data$created$w;

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

//
//
//
//
Expand Down Expand Up @@ -194,7 +199,7 @@ if (false) {(function () {
*
*/

/* harmony default export */ __webpack_exports__["a"] = ({
/* harmony default export */ __webpack_exports__["a"] = (_props$data$created$w = {

props: {
id: String,
Expand All @@ -214,6 +219,7 @@ if (false) {(function () {
placeholder: String,
required: Boolean,

model: '',
// Intial Value
initValue: {
type: String,
Expand Down Expand Up @@ -270,6 +276,11 @@ if (false) {(function () {
default: 0
},

disabled: {
type: Boolean,
default: false
},

// Create a custom template from data.
onShouldRenderChild: Function,

Expand Down Expand Up @@ -299,14 +310,22 @@ if (false) {(function () {
};
},


created: function created() {
// We initially sync the internalValue with the value passed in by the parent
this.model = this.type;
},
watch: {
type: function type() {
// When the type value changes, we $emit an event. Because this event is
// named 'input', v-model will automatically update the parent value
this.$emit('input', this.type);
},
options: function options(newVal, oldVal) {
if (this.filterByAnchor) {
var type = this.type,
anchor = this.anchor;

var regex = new RegExp("" + type, 'i');
var regex = new RegExp('' + type, 'i');
var filtered = newVal.filter(function (item) {
var found = item[anchor].search(regex) !== -1;
return found;
Expand All @@ -317,14 +336,13 @@ if (false) {(function () {
}
}
},

methods: {
getClassName: function getClassName(part) {
var classes = this.classes,
className = this.className;

if (classes[part]) return "" + classes[part];
return className ? className + "-" + part : '';
if (classes[part]) return '' + classes[part];
return className ? className + '-' + part : '';
},


Expand Down Expand Up @@ -444,7 +462,7 @@ if (false) {(function () {
},
activeClass: function activeClass(i) {
var focusClass = i === this.focusList ? 'focus-list' : '';
return "" + focusClass;
return '' + focusClass;
},
selectList: function selectList(data) {
// Deep clone of the original object
Expand Down Expand Up @@ -475,10 +493,10 @@ if (false) {(function () {
var encode = function encode(val) {
return _this3.encodeParams ? encodeURIComponent(val) : val;
};
var params = this.param + "=" + encode(val);
var params = this.param + '=' + encode(val);
if (this.customParams) {
Object.keys(this.customParams).forEach(function (key) {
params += "&" + key + "=" + encode(_this3.customParams[key]);
params += '&' + key + '=' + encode(_this3.customParams[key]);
});
}
return params;
Expand All @@ -501,7 +519,7 @@ if (false) {(function () {
var params = this.composeParams(val);
// Init Ajax
var ajax = new XMLHttpRequest();
ajax.open('GET', this.url + "?" + params, true);
ajax.open('GET', this.url + '?' + params, true);
this.composeHeader(ajax);
// Callback Event
ajax.addEventListener('progress', function (data) {
Expand Down Expand Up @@ -536,16 +554,14 @@ if (false) {(function () {
});
}
}
},

created: function created() {
// Sync parent model with initValue Props
this.type = this.initValue ? this.initValue : null;
},
mounted: function mounted() {
if (this.required) this.$refs.input.setAttribute("required", this.required);
}
});

}, _defineProperty(_props$data$created$w, 'created', function created() {
// Sync parent model with initValue Props
this.type = this.initValue ? this.initValue : null;
}), _defineProperty(_props$data$created$w, 'mounted', function mounted() {
if (this.required) this.$refs.input.setAttribute("required", this.required);
}), _props$data$created$w);

/***/ }),
/* 2 */
Expand Down Expand Up @@ -676,7 +692,8 @@ var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._sel
"id": _vm.id,
"placeholder": _vm.placeholder,
"name": _vm.name,
"autocomplete": "off"
"autocomplete": "off",
"disabled": _vm.disabled
},
domProps: {
"value": (_vm.type)
Expand Down
5 changes: 4 additions & 1 deletion src/js/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
:classes="{ input: 'form-control', wrapper: 'input-wrapper'}"
:process="processJSON"
:onSelect="handleSelect"
:disabled="false"
v-model="model"
>
</autocomplete>

<pre v-if="preContent" :style="preStyle">

<b>Selected Data:</b>
{{ preContent }}
</pre>
Expand All @@ -30,6 +32,7 @@

data () {
return {
model: '',
preContent: "",
preStyle: {
background: "#f2f2f2",
Expand Down
22 changes: 18 additions & 4 deletions src/js/components/vue-autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
:name="name"
v-model="type"
@input="handleInput"
@dblclick="handleDoubleClick"
@click="handleClick"
@blur="handleBlur"
@keydown="handleKeyDown"
@focus="handleFocus"
autocomplete="off"
:disabled="disabled"
/>

<div
Expand Down Expand Up @@ -73,6 +74,7 @@
placeholder: String,
required: Boolean,

model: '',
// Intial Value
initValue: {
type: String,
Expand Down Expand Up @@ -129,6 +131,11 @@
default: 0
},

disabled:{
type: Boolean,
default: false,
},

// Create a custom template from data.
onShouldRenderChild: Function,

Expand Down Expand Up @@ -157,8 +164,16 @@
debounceTask: undefined,
};
},

created: function() {
// We initially sync the internalValue with the value passed in by the parent
this.model = this.type;
},
watch: {
type() {
// When the type value changes, we $emit an event. Because this event is
// named 'input', v-model will automatically update the parent value
this.$emit('input', this.type)
},
options(newVal, oldVal) {
if (this.filterByAnchor) {
const { type, anchor } = this
Expand All @@ -173,7 +188,6 @@
}
}
},

methods: {

getClassName(part) {
Expand Down Expand Up @@ -271,7 +285,7 @@
LIST EVENTS
=============================*/

handleDoubleClick(){
handleClick(){
this.json = [];
this.getData("")
// Callback Event
Expand Down
68 changes: 2 additions & 66 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,6 @@ babel-helper-builder-binary-assignment-operator-visitor@^6.24.1:
babel-runtime "^6.22.0"
babel-types "^6.24.1"

babel-helper-builder-react-jsx@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-helper-builder-react-jsx/-/babel-helper-builder-react-jsx-6.24.1.tgz#0ad7917e33c8d751e646daca4e77cc19377d2cbc"
dependencies:
babel-runtime "^6.22.0"
babel-types "^6.24.1"
esutils "^2.0.0"

babel-helper-call-delegate@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d"
Expand Down Expand Up @@ -496,11 +488,7 @@ babel-plugin-syntax-export-extensions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-export-extensions/-/babel-plugin-syntax-export-extensions-6.13.0.tgz#70a1484f0f9089a4e84ad44bac353c95b9b12721"

babel-plugin-syntax-flow@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d"

babel-plugin-syntax-jsx@^6.1.18, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0:
babel-plugin-syntax-jsx@^6.1.18:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"

Expand Down Expand Up @@ -738,48 +726,13 @@ babel-plugin-transform-export-extensions@^6.22.0:
babel-plugin-syntax-export-extensions "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-flow-strip-types@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf"
dependencies:
babel-plugin-syntax-flow "^6.18.0"
babel-runtime "^6.22.0"

babel-plugin-transform-object-rest-spread@^6.22.0, babel-plugin-transform-object-rest-spread@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.23.0.tgz#875d6bc9be761c58a2ae3feee5dc4895d8c7f921"
dependencies:
babel-plugin-syntax-object-rest-spread "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-react-display-name@^6.23.0:
version "6.25.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.25.0.tgz#67e2bf1f1e9c93ab08db96792e05392bf2cc28d1"
dependencies:
babel-runtime "^6.22.0"

babel-plugin-transform-react-jsx-self@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx-self/-/babel-plugin-transform-react-jsx-self-6.22.0.tgz#df6d80a9da2612a121e6ddd7558bcbecf06e636e"
dependencies:
babel-plugin-syntax-jsx "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-react-jsx-source@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx-source/-/babel-plugin-transform-react-jsx-source-6.22.0.tgz#66ac12153f5cd2d17b3c19268f4bf0197f44ecd6"
dependencies:
babel-plugin-syntax-jsx "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-react-jsx@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx/-/babel-plugin-transform-react-jsx-6.24.1.tgz#840a028e7df460dfc3a2d29f0c0d91f6376e66a3"
dependencies:
babel-helper-builder-react-jsx "^6.24.1"
babel-plugin-syntax-jsx "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-regenerator@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.24.1.tgz#b8da305ad43c3c99b4848e4fe4037b770d23c418"
Expand Down Expand Up @@ -822,23 +775,6 @@ babel-preset-es2015@^6.24.1:
babel-plugin-transform-es2015-unicode-regex "^6.24.1"
babel-plugin-transform-regenerator "^6.24.1"

babel-preset-flow@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-preset-flow/-/babel-preset-flow-6.23.0.tgz#e71218887085ae9a24b5be4169affb599816c49d"
dependencies:
babel-plugin-transform-flow-strip-types "^6.22.0"

babel-preset-react@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-preset-react/-/babel-preset-react-6.24.1.tgz#ba69dfaea45fc3ec639b6a4ecea6e17702c91380"
dependencies:
babel-plugin-syntax-jsx "^6.3.13"
babel-plugin-transform-react-display-name "^6.23.0"
babel-plugin-transform-react-jsx "^6.24.1"
babel-plugin-transform-react-jsx-self "^6.22.0"
babel-plugin-transform-react-jsx-source "^6.22.0"
babel-preset-flow "^6.23.0"

babel-preset-stage-1@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-preset-stage-1/-/babel-preset-stage-1-6.24.1.tgz#7692cd7dcd6849907e6ae4a0a85589cfb9e2bfb0"
Expand Down Expand Up @@ -1941,7 +1877,7 @@ esprima@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"

esutils@^2.0.0, esutils@^2.0.2:
esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"

Expand Down