bedrock-angular-selector
A bedrock AngularJS module that provides a base directive for building custom UIs for selecting a particular item from a set of items.
This base directive provides:
- A customizable display for the selected item
- A UI for bringing up a modal to change the selection
- A customizable display within that modal for displaying the other choices
- A UI for triggering a customizable display for adding a new item to choose
Writing a Custom Selector
In this example, we'll be creating a selector to pick an image from a list of images. Creating a custom selector is typically a three step process:
- Create an "inner" selector directive that extends the
brSelector
base directive. This "inner" directive will requirebrSelector
and provide most of the custom selection implementation. An "outer" directive will supply thebrSelector
, hiding this implementation detail. This approach simplifies the code and cognitive load necessary to create a custom selector in an application.
var module = angular; module;
- Create the "outer" selector directive. This is the directive that will be used in your application.
angular;
The HTML template:
<!-- Create the br-selector directive and our inner directive; br-selected is an express that gets evaluated whenever the selection is changed, so set our `selected` variable to the new selection (brSelector.selected) when this happens. --> <!-- Define the HTML to display the selected item by specifying name="br-selector-selected"; br-selector will look for this value to perform transclusion. You can optionally specify `br-lazy-compile`, if you've included it (bedrock-angular-lazy-compile), to prevent angular from doing any unnecessary compiling until the first selection is made. --> <!-- Define the HTML to display the items available for selection by specifying name="br-selector-choices"; br-selector will look for this value to perform transclusion. You can optionally specify `br-lazy-compile` here as well. --> <!-- This could be a grid display, involve pagination, or whatever is appropriate for showing items for selection. --> <!-- When "Add" is clicked in the base selector UI, open this modal. When the modal closes, if there was no error, change the selection by selecting the result (which will be the new image). --> <!-- Modal contents with UI to add an image. --> Enter the URL for the image. Add Cancel
- Use your selector directive in your application.
Setup
bower install bedrock-angular-selector
Installation of the module followed by a restart of your bedrock server is sufficient to make the module available to your application.
To manually add bedrock-angular-selector as a dependency:
angular;