feat: new autocomplete control

This commit is contained in:
Saqib Ansari 2022-01-24 17:21:15 +05:30
parent 3cf3489172
commit 10edae6524
5 changed files with 20 additions and 4 deletions

View file

@ -98,7 +98,7 @@
"label": "Type",
"oldfieldname": "fieldtype",
"oldfieldtype": "Select",
"options": "Attach\nAttach Image\nBarcode\nButton\nCheck\nCode\nColor\nColumn Break\nCurrency\nData\nDate\nDatetime\nDuration\nDynamic Link\nFloat\nFold\nGeolocation\nHeading\nHTML\nHTML Editor\nIcon\nImage\nInt\nLink\nLong Text\nMarkdown Editor\nPassword\nPercent\nRead Only\nRating\nSection Break\nSelect\nSignature\nSmall Text\nTab Break\nTable\nTable MultiSelect\nText\nText Editor\nTime",
"options": "Autocomplete\nAttach\nAttach Image\nBarcode\nButton\nCheck\nCode\nColor\nColumn Break\nCurrency\nData\nDate\nDatetime\nDuration\nDynamic Link\nFloat\nFold\nGeolocation\nHeading\nHTML\nHTML Editor\nIcon\nImage\nInt\nLink\nLong Text\nMarkdown Editor\nPassword\nPercent\nRead Only\nRating\nSection Break\nSelect\nSignature\nSmall Text\nTab Break\nTable\nTable MultiSelect\nText\nText Editor\nTime",
"reqd": 1,
"search_index": 1
},
@ -540,7 +540,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-01-03 11:56:19.812863",
"modified": "2022-01-04 11:56:19.812863",
"modified_by": "Administrator",
"module": "Core",
"name": "DocField",

View file

@ -52,7 +52,8 @@ class MariaDBDatabase(Database):
'Barcode': ('longtext', ''),
'Geolocation': ('longtext', ''),
'Duration': ('decimal', '21,9'),
'Icon': ('varchar', self.VARCHAR_LEN)
'Icon': ('varchar', self.VARCHAR_LEN),
'Autocomplete': ('varchar', self.VARCHAR_LEN),
}
def get_connection(self):

View file

@ -35,7 +35,8 @@ data_fieldtypes = (
'Barcode',
'Geolocation',
'Duration',
'Icon'
'Icon',
'Autocomplete'
)
attachment_fieldtypes = (

View file

@ -15,6 +15,17 @@ frappe.ui.form.ControlAutocomplete = class ControlAutoComplete extends frappe.ui
}
}
format_for_input(value) {
if (value == null) {
return "";
} else if (this._data && this._data.length) {
const item = this._data.find(i => i.value == value);
return item ? item.label : value;
} else {
return value;
}
}
get_awesomplete_settings() {
var me = this;
return {

View file

@ -21,6 +21,9 @@ frappe.form.formatters = {
}
return value==null ? "" : value;
},
Autocomplete: function(value) {
return __(frappe.form.formatters["Data"](value));
},
Select: function(value) {
return __(frappe.form.formatters["Data"](value));
},