_checkList
Display a checklist of items to add or remove from a Set. --
Function
Thing Type -> Thing Type._checkList
(on, selectedOnly, display, filterField, addModel) -> The same Type
- Receives -- Thing Type
- The items to choose from.
: Defining Context : The Property that actually contains the checklist, which should be a Set of Things
- on
- The Thing that contains the Set.
- selectedOnly (optional)
- If True, only items currently in the Set will be displayed.
- display (optional)
- How to display each item.
- filterField (optional)
- If specified, the ID of a text field to filter on
- addModel (optional)
- If specified, you can type names in the
filterField
, and new Instances of this Model will be created
- Produces
- The Check List, ready to display.
Sometimes, you want to be able to take a Set, and use it as a checklist. The _checkList
function is designed for that.
For example, say that you have a Shopping List Space. There is a Shopping Item Model, with an Instance
for each item that you sometimes shop for, and a Shops Tag Set saying where it can be found.
You have a Thing named "Shopping List", with a Property "Contents", which is a Set of Things.
You would display the whole shopping list, as a checklist, like this:
[[Shopping Item._instances -> Contents.checkList(on = Shopping List)]]
That is, the actual list is found in Shopping List.Contents, and you are choosing from
all Instances of Shopping Item. This lets you easily add Items to the list.
Sometimes, you only want to list the items that are actually checked-off. For example, when
you go shopping, you just want to be checking things off the list. So you would say:
[[Shopping Item._instances -> Contents._checkList(on = Shopping List, selectedOnly = true)]]
By using selectedOnly
like this, it will only display the currently-selected Items, so
you can check them off.
You can filter which items show on the list. For instance, you could show a list of just the
Items to look for at Acme like this:
[[Shopping Item._instances
-> _filter(Shops -> _contains(Acme))
-> Contents._checkList(on = Shopping List, selectedOnly = true)]]
This way, you can easily display customized checklists for particular situations.
You can also create a live filter-by-name. If you specify the filterField
parameter, that should point
to a _textInput that you can type into, to filter down the items being currently shown in the checklist.
You can also use the filterField
to add new items. If you add the addModel
parameter, that specifies
the model for the items in this list; if you type in a new name in the filterField
and press Enter, a
new instance of that model will be created, with the given name, and added to the checklist.
So putting those together, you can specify a full shopping list, that lets you filter the items being
shown and add new one on the fly, like this:
[[_textInput(id = ""itemfilter"", placeholder = ""Filter or add items"")]]
[[Shopping Item._instances ->
Shopping Items._checkList(on = Shopping List, filterField = ""itemfilter"", addModel = Shopping Item)]]
By default, _checkList will display show each item's Name. But you can customize this using
the display
parameter. If provided, this will be applied to every item, and the result is
what will be shown.