ソースを参照

New Control: MultiSelect (#4425)

* New Control: MultiSelect

* fix codacy
version-14
Faris Ansari 7年前
committed by GitHub
コミット
ab8de1d83f
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
4個のファイルの変更54行の追加19行の削除
  1. +2
    -1
      frappe/public/build.json
  2. +3
    -0
      frappe/public/css/list.css
  3. +20
    -18
      frappe/public/js/frappe/form/controls/autocomplete.js
  4. +29
    -0
      frappe/public/js/frappe/form/controls/multiselect.js

+ 2
- 1
frappe/public/build.json ファイルの表示

@@ -54,7 +54,8 @@
"public/js/frappe/form/controls/heading.js",
"public/js/frappe/form/controls/autocomplete.js",
"public/js/frappe/form/controls/barcode.js",
"public/js/frappe/form/controls/geolocation.js"
"public/js/frappe/form/controls/geolocation.js",
"public/js/frappe/form/controls/multiselect.js"
],
"js/dialog.min.js": [
"public/js/frappe/dom.js",


+ 3
- 0
frappe/public/css/list.css ファイルの表示

@@ -34,11 +34,14 @@
}
.set-filters .btn-group {
margin-right: 10px;
white-space: nowrap;
font-size: 0;
}
.set-filters .btn-group .btn-default {
background-color: transparent;
border: 1px solid #d1d8dd;
color: #8D99A6;
float: none;
}
.filter-box {
border-bottom: 1px solid #d1d8dd;


+ 20
- 18
frappe/public/js/frappe/form/controls/autocomplete.js ファイルの表示

@@ -2,30 +2,32 @@ frappe.ui.form.ControlAutocomplete = frappe.ui.form.ControlData.extend({
make_input() {
this._super();
this.setup_awesomplete();
this.set_options();
},

setup_awesomplete() {
var me = this;
set_options() {
if (this.df.options) {
let options = this.df.options || [];
if(typeof options === 'string') {
options = options.split('\n');
}
this._data = options;
}
},

this.awesomplete = new Awesomplete(this.input, {
get_awesomplete_settings() {
return {
minChars: 0,
maxItems: 99,
autoFirst: true,
list: this.get_data(),
data: function (item) {
if (typeof item === 'string') {
item = {
label: item,
value: item
};
}

return {
label: item.label || item.value,
value: item.value
};
}
});
list: this.get_data()
};
},

setup_awesomplete() {
var me = this;

this.awesomplete = new Awesomplete(this.input, this.get_awesomplete_settings());

$(this.input_area).find('.awesomplete ul').css('min-width', '100%');



+ 29
- 0
frappe/public/js/frappe/form/controls/multiselect.js ファイルの表示

@@ -0,0 +1,29 @@
frappe.ui.form.ControlMultiSelect = frappe.ui.form.ControlAutocomplete.extend({
get_awesomplete_settings() {
const settings = this._super();

return Object.assign(settings, {
filter: function(text, input) {
return Awesomplete.FILTER_CONTAINS(text, input.match(/[^,]*$/)[0]);
},

item: function(text, input) {
return Awesomplete.ITEM(text, input.match(/[^,]*$/)[0]);
},

replace: function(text) {
const before = this.input.value.match(/^.+,\s*|/)[0];
this.input.value = before + text + ", ";
}
});
},

get_data() {
const value = this.get_value() || '';
const values = value.split(', ').filter(d => d);
const data = this._super();

// return values which are not already selected
return data.filter(d => !values.includes(d));
}
});

読み込み中…
キャンセル
保存