keyValueSelector

Syntax

monster.ui.keyValueSelector(args)

Parameters

args is a mandatory Object parameter with the following properties:

KeyDescriptionTypeDefaultRequired
isEditableWhether new categories can be added (set to true when choices is empty/not provided).Booleanfalsefalse
existingMap existing categories to existing items (generated form choices when not provided).Objectfalse
existing[]List of existing items per category.Array(String())true
choicesList of categories/items to render.Array(#/choice)false
i18nCustom internationalization labels.Object(#/i18n)false
normalizerUsed to normalize user input for comparison against existing category/item IDs.Functionlodash#snakeCasefalse
onSelectCallback on select action, invoked with two parameters exposing the category/item selected: (caterogy, item)Functionfalse

choice

KeyDescriptionTypeDefaultRequired
idCategory identifier.Stringtrue
labelCategory label.Stringtrue
isEditableWhether new items can be added for this category.Booleanfalsefalse
itemsCategory label.Arraytrue
items[]Objecttrue
items[].idItem identifier.Stringtrue
items[].labelItem label.Stringtrue

i18n

KeyDescriptionTypeDefaultRequired
titleDialog title label.StringSelect a pair of category/itemfalse
categoriesCategories title labelStringCategoriesfalse
itemsItems title label.StringItemsfalse
newCategoryNew category radio label.StringNew Categoryfalse
newItemNew item radio label.StringNew Itemfalse
categoryNameNew category input placeholder.StringCategory Namefalse
itemNameNew item input placeholder.StringItem Namefalse
cancelCancel button label.StringCancelfalse
selectSelect button label.StringSelectfalse

Description

Example

var existing = {
    fruits: [
        'apple', 'peach', 'pear', 'clementine', 'banana'
    ],
    vegetables: [
        'lettuce', 'aspargus', 'chard', 'spinach', 'broccoli'
    ],
    meats: [
        'veal', 'bison', 'chicken', 'beef', 'pork'
    ]
};

monster.ui.keyValueSelector({
    onSelect: function(key, value) {
        window.alert('category: ' + key + '\nitem: ' + value);
    },
    isEditable: true,
    choices: _
        .chain(existing)
        .keys()
        .map(function(category) {
            return {
                id: category,
                label: _.startCase(category),
                isEditable: true,
                items: _
                    .chain(existing)
                    .get(category)
                    .map(function(item) {
                        return {
                            id: item,
                            label: _.startCase(item)
                        };
                    })
                    .sortBy('label')
                    .value()
            };
        })
        .sortBy('label')
        .value()
});

On this page