Skip to content

Commit 386a627

Browse files
committed
[2.6.0] Added <Autocomplete /> control
1 parent 4b0a2e9 commit 386a627

File tree

12 files changed

+231
-13
lines changed

12 files changed

+231
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.6.0
2+
3+
- Added `<Autocomplete />` control
4+
15
## 2.5.11
26

37
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ See demo at [https://detools.github.io/vue-form](https://detools.github.io/vue-f
7979

8080
## Changelog
8181

82+
- [2.6.0](/CHANGELOG.md#260)
8283
- [2.5.11](/CHANGELOG.md#2511)
8384
- [2.5.10](/CHANGELOG.md#2510)
8485
- [2.5.9](/CHANGELOG.md#259)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { Autocomplete } from 'element-ui'
2+
import noop from 'lodash/noop'
3+
import isNull from 'lodash/isNull'
4+
import ConnectedControlMixin from '../mixins/ConnectedControl'
5+
6+
const ConnectedAutocomplete = {
7+
props: {
8+
name: {
9+
type: String,
10+
required: true,
11+
},
12+
13+
value: {
14+
type: [String, Number],
15+
default: '',
16+
},
17+
18+
labelKey: {
19+
type: String,
20+
default: 'name',
21+
},
22+
23+
valueKey: {
24+
type: String,
25+
default: 'id',
26+
},
27+
28+
placeholder: String,
29+
clearable: Boolean,
30+
disabled: Boolean,
31+
debounce: Number,
32+
placement: String,
33+
popperClass: String,
34+
triggerOnFocus: Boolean,
35+
selectWhenUnmatched: Boolean,
36+
prefixIcon: String,
37+
suffixIcon: String,
38+
hideLoading: Boolean,
39+
popperAppendToBody: Boolean,
40+
tabindex: Number,
41+
autofocus: Boolean,
42+
autosize: Boolean,
43+
autocomplete: {
44+
type: String,
45+
default: 'off',
46+
},
47+
size: String,
48+
49+
validators: Array,
50+
asyncValidators: Array,
51+
52+
fetchSuggestions: {
53+
type: Function,
54+
required: true,
55+
},
56+
57+
handleFocus: {
58+
type: Function,
59+
default: noop,
60+
},
61+
62+
handleBlur: {
63+
type: Function,
64+
default: noop,
65+
},
66+
67+
handleSelect: {
68+
type: Function,
69+
default: noop,
70+
},
71+
72+
/* FormItem Props */
73+
label: [String, Boolean],
74+
formItem: Boolean,
75+
labelWidth: String,
76+
},
77+
78+
mixins: [ConnectedControlMixin],
79+
80+
data() {
81+
return {
82+
viewValue: this.value,
83+
}
84+
},
85+
86+
methods: {
87+
handleFieldSelect(value) {
88+
const nextValue = isNull(this.valueKey) ? value : value[this.valueKey]
89+
90+
this.setTouched()
91+
this.handleSelect(nextValue)
92+
93+
this.viewValue = isNull(this.labelKey) ? value : value[this.labelKey]
94+
95+
const [, setValue] = this.state
96+
setValue(nextValue)
97+
},
98+
99+
renderComponent() {
100+
return (
101+
<Autocomplete
102+
class={this.class}
103+
name={this.name}
104+
type={this.type}
105+
value={this.viewValue}
106+
placeholder={this.placeholder}
107+
clearable={this.clearable}
108+
disabled={this.disabled}
109+
value-key={this.labelKey}
110+
debounce={this.debounce}
111+
placement={this.placement}
112+
popper-class={this.popperClass}
113+
trigger-on-focus={this.triggerOnFocus}
114+
select-when-unmatched={this.selectWhenUnmatched}
115+
prefix-icon={this.prefixIcon}
116+
suffix-icon={this.suffixIcon}
117+
hide-loading={this.hideLoading}
118+
popper-append-to-body={this.popperAppendToBody}
119+
tabindex={this.tabindex}
120+
autofocus={this.autofocus}
121+
autosize={this.autosize}
122+
autocomplete={this.autocomplete}
123+
size={this.size}
124+
fetch-suggestions={this.fetchSuggestions}
125+
on-focus={this.handleFocus}
126+
on-blur={this.handleFieldBlur}
127+
on-select={this.handleFieldSelect}>
128+
{Boolean(this.prefix) && <template slot="prefix">{this.prefix}</template>}
129+
{Boolean(this.suffix) && <template slot="suffix">{this.suffix}</template>}
130+
{Boolean(this.append) && <template slot="append">{this.append}</template>}
131+
{Boolean(this.prepend) && <template slot="prepend">{this.prepend}</template>}
132+
</Autocomplete>
133+
)
134+
},
135+
},
136+
}
137+
138+
export default ConnectedAutocomplete

VueForm/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Checkbox from './components/ConnectedCheckbox'
55
import CheckboxGroup from './components/ConnectedCheckboxGroup'
66
import Input from './components/ConnectedInput'
77
import InputNumber from './components/ConnectedInputNumber'
8+
import Autocomplete from './components/ConnectedAutocomplete'
89
import Select from './components/ConnectedSelect'
910
import Switch from './components/ConnectedSwitch'
1011
import Slider from './components/ConnectedSlider'
@@ -24,6 +25,7 @@ export {
2425
CheckboxGroup,
2526
Input,
2627
InputNumber,
28+
Autocomplete,
2729
Select,
2830
Switch,
2931
Slider,

docs/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/main.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11

2-
.root-container[data-v-434ec9e2] {
2+
.root-container[data-v-a1275c98] {
33
min-height: 100%;
44
}
5-
.title[data-v-434ec9e2] {
5+
.title[data-v-a1275c98] {
66
font-size: 40px;
77
margin: 10px 0 0;
88
font-weight: bold;
99
}
10-
.main-container[data-v-434ec9e2] {
10+
.main-container[data-v-a1275c98] {
1111
display: flex;
1212
flex-direction: row;
1313
justify-content: space-between;
1414
align-items: stretch;
1515
}
16-
.aside[data-v-434ec9e2] {
16+
.aside[data-v-a1275c98] {
1717
border-top: 1px solid rgba(0, 0, 0, 0.1);
1818
}
19-
.main[data-v-434ec9e2] {
19+
.main[data-v-a1275c98] {
2020
padding: 10px 40px 40px;
2121
border-top: 1px solid rgba(0, 0, 0, 0.1);
2222
border-left: 1px solid rgba(0, 0, 0, 0.1);
2323
}
24-
.link[data-v-434ec9e2] {
24+
.link[data-v-a1275c98] {
2525
display: block;
2626
line-height: 40px;
2727
padding-left: 30px;
2828
position: relative;
2929
color: #0a0a0a;
3030
}
31-
.link_active[data-v-434ec9e2]:before {
31+
.link_active[data-v-a1275c98]:before {
3232
content: '\261B';
3333
position: absolute;
3434
display: block;

docs/vendors~main.bundle.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default {
2020
'SyncValidationForm',
2121
'AllValidationsForm',
2222
'ArrayFieldForm',
23+
'AutocompleteForm',
2324
],
2425
}
2526
},
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import Form, { Autocomplete } from '@detools/vue-form'
2+
3+
export default {
4+
data() {
5+
return {
6+
formValues: {},
7+
}
8+
},
9+
10+
methods: {
11+
handleSubmit(values) {
12+
this.formValues = values
13+
},
14+
15+
fetchSuggestions(query, callback) {
16+
if (query !== '') {
17+
setTimeout(() => {
18+
callback(
19+
[
20+
{ id: 1, name: 'Leonard Leblanc' },
21+
{ id: 2, name: 'Mitzi Rocha' },
22+
{ id: 3, name: 'Marquita Giles' },
23+
].filter(({ name: item }) => item.toLowerCase().includes(query))
24+
)
25+
}, 500)
26+
} else {
27+
callback([])
28+
}
29+
},
30+
},
31+
32+
render() {
33+
return (
34+
<div>
35+
<h1>Sync Validation Form</h1>
36+
<div class="wrapper">
37+
<div class="form">
38+
<Form
39+
submit
40+
labelWidth="150px"
41+
labelPosition="left"
42+
labelSuffix=":"
43+
buttonsPosition="label"
44+
handleSubmit={this.handleSubmit}>
45+
<Autocomplete
46+
formItem
47+
name="username"
48+
label="Type A and wait"
49+
fetchSuggestions={this.fetchSuggestions}
50+
/>
51+
</Form>
52+
</div>
53+
<div class="values">
54+
<strong>Form Values</strong>
55+
<br />
56+
<br />
57+
<div>
58+
<pre>{JSON.stringify(this.formValues, null, 2)}</pre>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
)
64+
},
65+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default from './AutocompleteForm'

0 commit comments

Comments
 (0)