I would like to achieve something with the autocomplete control, but I have some issues and I would kindly ask for your help.
When I want to choose a value, and that value is not in the data source of the autocomplete, I have made the functionality to add new value, and after I add new value for it to be selected in the control.
At the moment, I can save the value in the source, but I still have to manually select that value in the autocomplete.
<template>
<div>
<div>
<div id="Modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="Modal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" style="display: block; float: right; padding: 5px 15px 0 0; border-bottom: none;">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size: 2.5em" :title="$t('Zatvori')"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<div>
<TemplatePerson ref="person"></TemplatePerson>
</div>
</div>
</div>
</div>
</div>
</div>
<form id="form_contract" v-on:submit.prevent="onSubmit" class="row">
<div class="col-md-12">
<div class="form-group row">
<!-- Dodati label u resurse -->
<label class="control-label col-md-2 text-right">Person</label>
<div class="col-md-8">
<ejs-autocomplete id="PERSON"
class="form-control obavezno"
:dataSource='PERSON_data'
:fields='PERSON_fields'
v-model="data.PERSON">
</ejs-autocomplete>
</div>
<div class="col-md-2 feedback m-t-5">
<button type="button" class="btn btn-outline-info btn-xs btn-circle" @click="openModal" :data-tooltip="$t('Add Person')" tabindex="-1"><i class="fa fa-plus"></i></button>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<button type="submit" class="btn btn-primary btn-md pull-right m-b-15 waves-effect">Save</button>
</div>
<div class="col-md-2">
</div>
</div>
</div>
</form>
</div>
</template>
<script>
import Vue from 'vue';
import { AutoCompletePlugin } from "@syncfusion/ej2-vue-dropdowns";
import { Query, DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
import TemplatePerson from './template.vue';
Vue.use(AutoCompletePlugin);
export default {
name: 'ContractGeneral',
components: {
TemplatePerson
},
data: function () {
return {
data: {
PERSON: '',
},
PERSON_data: new DataManager({
url: '/api/persons/personsOnCase',
crossDomain: true,
adaptor: new UrlAdaptor,
requestType: 'json',
}),
PERSON_fields: { text: 'value', value: 'id' },
}
},
methods: {
openModal: function () {
this.$refs.person.data.FIRST_NAME = '';
this.$refs.person.data.LAST_NAME = '';
if (this.data.PERSON) {
if (this.data.PERSON.split(" ").length - 1 == 1) {
var data = this.data.PERSON.split(' ');
this.$refs.person.data.FIRST_NAME = data[0];
this.$refs.person.data.LAST_NAME = data[1];
}
else {
this.$refs.person.data.FIRST_NAME = this.data.PERSON;
}
}
$("#Modal").modal("show");
},
onSubmit: function () {
console.log(this.data);
}
}
}
</script>
<style>
@import "../../node_modules/@syncfusion/ej2-vue-dropdowns/styles/bootstrap.css";
</style>