idField option for SimpleAutocomplete
parent
a905d1bf96
commit
63f3ce6c61
18
hinter.js
18
hinter.js
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete
|
Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete
|
||||||
License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/)
|
License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/)
|
||||||
Version: 2015-01-16
|
Version: 2015-03-25
|
||||||
(c) Vitaliy Filippov 2011-2015
|
(c) Vitaliy Filippov 2011-2015
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
@ -15,11 +15,12 @@
|
||||||
dataLoader(hint, value[, more])
|
dataLoader(hint, value[, more])
|
||||||
Callback which should load autocomplete options and then call:
|
Callback which should load autocomplete options and then call:
|
||||||
hint.replaceItems(newOptions, append)
|
hint.replaceItems(newOptions, append)
|
||||||
newOptions = [ [ name, value, disabled, checked ] ], [ name, value ], ... ]
|
newOptions = [ [ name, value, disabled, checked OR id ] ], [ name, value ], ... ]
|
||||||
name = HTML option name
|
name = HTML option name
|
||||||
value = plaintext option value
|
value = plaintext option value
|
||||||
disabled = prevent selection of this option
|
disabled = prevent selection of this option
|
||||||
checked = only meaningful when multipleListener is set
|
checked = (when multipleListener is set) is the item checked initially
|
||||||
|
id = (when idField is set) the value ID for idField
|
||||||
append = 'more' parameter should be passed here
|
append = 'more' parameter should be passed here
|
||||||
Callback parameters:
|
Callback parameters:
|
||||||
hint
|
hint
|
||||||
|
@ -61,6 +62,10 @@
|
||||||
of the list, and SimpleAutocomplete will issue another request to
|
of the list, and SimpleAutocomplete will issue another request to
|
||||||
dataLoader with incremented 'more' parameter when it will be clicked.
|
dataLoader with incremented 'more' parameter when it will be clicked.
|
||||||
You can also set moreMarker to false to disable this feature.
|
You can also set moreMarker to false to disable this feature.
|
||||||
|
idField
|
||||||
|
If you specify an ID here, the selected value ID will be put into
|
||||||
|
a hidden field with this ID, while the original hinted input will
|
||||||
|
just contain the name of that value.
|
||||||
persist
|
persist
|
||||||
If true, the hint layer will never be hidden. You can use it to create
|
If true, the hint layer will never be hidden. You can use it to create
|
||||||
multiselect-like controls (see example at the homepage).
|
multiselect-like controls (see example at the homepage).
|
||||||
|
@ -90,8 +95,11 @@ var SimpleAutocomplete = function(input, dataLoader, params)
|
||||||
this.prompt = params.prompt;
|
this.prompt = params.prompt;
|
||||||
this.delay = params.delay;
|
this.delay = params.delay;
|
||||||
this.moreMarker = params.moreMarker;
|
this.moreMarker = params.moreMarker;
|
||||||
|
this.idField = params.idField;
|
||||||
this.persist = params.persist;
|
this.persist = params.persist;
|
||||||
this.className = params.className || 'hintLayer';
|
this.className = params.className || 'hintLayer';
|
||||||
|
if (this.idField && typeof(this.idField) == 'string')
|
||||||
|
this.idField = document.getElementById(this.idField);
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
if (this.moreMarker === undefined)
|
if (this.moreMarker === undefined)
|
||||||
|
@ -317,6 +325,8 @@ SimpleAutocomplete.prototype.selectItem = function(index)
|
||||||
if (!this.multipleDelimiter && !this.multipleListener)
|
if (!this.multipleDelimiter && !this.multipleListener)
|
||||||
{
|
{
|
||||||
this.input.value = this.items[index][1];
|
this.input.value = this.items[index][1];
|
||||||
|
if (this.idField)
|
||||||
|
this.idField.value = this.items[index][3];
|
||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -455,6 +465,8 @@ SimpleAutocomplete.prototype.onChange = function(force)
|
||||||
this.more = 0;
|
this.more = 0;
|
||||||
if (v != this.curValue || force)
|
if (v != this.curValue || force)
|
||||||
{
|
{
|
||||||
|
if (this.idField)
|
||||||
|
this.idField.value = '';
|
||||||
this.curValue = v;
|
this.curValue = v;
|
||||||
if (!this.delay || force)
|
if (!this.delay || force)
|
||||||
this.dataLoader(this, v, this.more);
|
this.dataLoader(this, v, this.more);
|
||||||
|
|
Loading…
Reference in New Issue