I have an autocomplete that load and saves just fine. The problem is when I come back to the screen to edit the page, I am losing the value of the autocomplete.
MVC View
Javascript setting up field
Javascript to set value to the field when coming back to the screen to edit
I need someway to get at that dataItem that was just set to the field and set it to the window variable, but I can't seem to make it work
MVC View
<
input
type
=
"text"
id
=
"clientContactAutoComplete"
class
=
"k-autocomplete"
/>
$(
"#clientContactAutoComplete"
).kendoAutoComplete({
minlength: 4,
placeholder:
"Select Client Contact"
,
dataSource:
new
kendo.data.DataSource({
serverFiltering:
true
,
transport: {
read: {
url:
'/DataService/LoadContacts'
,
dataType:
"json"
},
parameterMap:
function
() {
return
{
search: $(
"#clientContactAutoComplete"
).data(
"kendoAutoComplete"
).value()
};
},
},
pageSize: 10
}),
dataTextField:
"FullName"
,
template: kendo.template($(
"#clientContactTemplate"
).html()),
style:
"width: 300px"
,
select:
function
(e) {
window.clientContactAutoCompleteDataItem =
this
.dataItem(e.item.index());
// this is the window variable I need to set /////////////////////////
var
fullName = window.clientContactAutoCompleteDataItem.FirstName;
if
(window.clientContactAutoCompleteDataItem.MiddleName !=
null
) {
fullName = fullName +
" "
+ window.clientContactAutoCompleteDataItem.MiddleName;
}
if
(window.clientContactAutoCompleteDataItem.LastName !=
null
) {
fullName = fullName +
" "
+ window.clientContactAutoCompleteDataItem.LastName;
}
window.clientContactAutoCompleteDataItem.FullName = fullName;
// Add DSR information to the display part of the grid if necessary.
if
(!pipelineUtilities.isNullOrEmpty(window.clientContactAutoCompleteDataItem.DSRConsultantName)) {
window.clientContactAutoCompleteDataItem.FullName = window.clientContactAutoCompleteDataItem.FullName +
" {DSR - "
+ window.clientContactAutoCompleteDataItem.DSRConsultantName +
"}"
;
}
GetOffLimitsText();
},
}).data(
"kendoAutoComplete"
);
// get the object
var
clientAC = $(
"#clientContactAutoComplete"
).data(
"kendoAutoComplete"
);
// set the saved value to the field
clientAC.value(window.ClientFullName); ---
this
is working
// get the selected dataItem and set it to the window variable
clientAC.search(window.ClientFullName);
window.clientContactAutoCompleteDataItem = clientAC.dataItem(0); ---
this
is failing
I need someway to get at that dataItem that was just set to the field and set it to the window variable, but I can't seem to make it work