Code:
{define-proc public {filter-complete
list:StringArray,
prefix:String = "",
sort?:bool = true,
remove-blank?:bool = true
}:StringArray
let values:Set = {Set} || Set of unique values
let value-list:StringArray = {StringArray} || Values in order seen
{for fv in list do
{if fv == "" and remove-blank? then
{continue}
}
{if not {values.member? fv} and
{fv.prefix? prefix, ignore-case? = true}
then
{value-list.append fv}
{values.insert fv}
}
}
{if sort? then
{value-list.sort}
}
{return value-list}
}
{define-class public open SimpleStringCellProvider
{inherits AutocompleteProvider}
field list:StringArray
field protected cell:RecordGridCell
{constructor public {default
cell:RecordGridCell,
max-results:int,
list:StringArray
}
{construct-super max-results}
set self.cell = cell
set self.list = list
}
{method public open {refresh acf:AutocompleteMixin}:void
{if-non-null record = self.cell.record then
{if-non-null rs = record.record-set then
{acf.populate-from-strings
{filter-complete
self.list,
prefix = acf.text-field.value
}
}
{return}
}
}
{acf.populate-from-strings {StringArray}}
}
}
{define-class public ExAutocompleteStringCell
{inherits AutocompleteStringCell}
field count:int = 10
field list:StringArray = {StringArray}
{constructor public {default }
}
{method public {create-editor}:TextField
let editor:TextField =
{super.create-editor} asa TextField
set (editor asa SRGAutocompleteTextField).provider =
{SimpleStringCellProvider
self,
self.count,
self.list
}
{return editor}
}
}
{define-class public SimpleCompleteCell
{inherits ExAutocompleteStringCell}
{constructor public {default }
set self.list = {StringArray "aaa", "aab", "abb", "abc"}
}
}