dropdown_list_widget: Add a `include_current_item` parameter.

Added a `include_current_item` parameter to dropdown_list_widget
which behaves as follows:

- Has a default value of `true`, which includes the current value
in the dropdown list items.
- If set to false, it excludes the current value from dropdown
list items.
This commit is contained in:
aryanshridhar 2021-03-28 18:54:00 +05:30 committed by Tim Abbott
parent ddbb0a5fbc
commit c630b888e5
1 changed files with 8 additions and 1 deletions

View File

@ -11,6 +11,7 @@ export const DropdownListWidget = function ({
default_text, default_text,
render_text = (item_name) => item_name, render_text = (item_name) => item_name,
null_value = null, null_value = null,
include_current_item = true,
value, value,
on_update = () => {}, on_update = () => {},
}) { }) {
@ -86,8 +87,14 @@ export const DropdownListWidget = function ({
).expectOne(); ).expectOne();
const search_input = $(`#${CSS.escape(container_id)} .dropdown-search > input[type=text]`); const search_input = $(`#${CSS.escape(container_id)} .dropdown-search > input[type=text]`);
const dropdown_toggle = $(`#${CSS.escape(container_id)} .dropdown-toggle`); const dropdown_toggle = $(`#${CSS.escape(container_id)} .dropdown-toggle`);
const get_data = (data) => {
if (include_current_item) {
return data;
}
return data.filter((x) => x.value !== value.toString());
};
ListWidget.create(dropdown_list_body, data, { ListWidget.create(dropdown_list_body, get_data(data), {
name: `${CSS.escape(widget_name)}_list`, name: `${CSS.escape(widget_name)}_list`,
modifier(item) { modifier(item) {
return render_dropdown_list({item}); return render_dropdown_list({item});