Reusable Accessible Mapping Platform

API Docs for: 5.3.2
Show:

ChoiceBrick Class

Extends Brick
Module: Bricks
Parent Module: Utils

The ChoiceBrick prototype. Provides a user the ability to choose a single item among several. To instantiate, call new on the ChoiceBrick prototype.

Imports RAMP Modules:

Util
TmplHelper
Array
Dictionary

Uses RAMP Templates:

templates/bricks_template.json

Methods

clear

() ChoiceBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1191

Clears the ChoiceBrick by reseting selectedChoice to an empty string and userSelected to false.

Returns:

ChoiceBrick:

itself

disable

(
  • disable
  • force
)
Brick chainable

Disables or re-enables the Brick.

Parameters:

  • disable Boolean

    true to disable; false to enable

  • force Boolean

    if true, disables the brick even if it's frozen

Returns:

Brick:

itself

displayNotice

(
  • notice
  • [noticeTemplate]
)
Brick chainable

Display a (error) notice on the brick.

Parameters:

  • notice Object

    object with notice data to be passed to the template

  • [noticeTemplate] String optional

    notice template name

Returns:

Brick:

itself

getData

(
  • [wrap]
)
Object

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1232

Returns ChoiceBrick's data.

Parameters:

  • [wrap] Boolean optional

    indicates of the payload should be wrapped with a Brick's id; useful when collection information from several Bricks at once.

Returns:

Object:

A wrapper object around two properties: selectedChoice and userSelected

isUserSelected

() ChoiceBrick chainable

Checks if the option was selected by the user or not.

Returns:

ChoiceBrick:

itself

isValid

() Boolean

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1206

Checks if the brick is valid. The ChoiceBrick is considered valid if selectedChoice is not an empty String.

Returns:

Boolean:

true if valid; false if not

new

(
  • id
  • config
)
ChoiceBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1104

Initializes the ChoiceBrick by generating a specified template and setting defaults. Also sets a click listener on the template button. The ChoiceBrick prototype. Provides a user the ability to choose a single item among several.

Parameters:

  • id String

    specified id of the Brick

  • config Object

    a configuration object for the Brick

    • [header] String optional

      a Brick header

    • [instructions] String optional

      a configuration object for the Brick

    • [required] Array | Object optional

      collection of rules specifying what external conditions must be valid for the Brick to be enabled

    • [freezeStates] Array optional

      a set of rules specifying states Brick should be frozen

    • [baseTemplate] String optional

      a base template name to be used

    • [noticeTemplate] String optional

      a notice template name to be used

    • [containerClass] String optional

      a CSS class of the specific brick container

    • [template] String optional

      a name of the specific Brick template

    • [choices] Array optional

      a set of choices that will be presented to the user

Returns:

notify

(
  • eventName
  • data
)
Brick private chainable

Notifies a listener of a Brick event.

Parameters:

  • eventName String

    an eventName that should be reported

  • data Object

    a payload object to be passed along with the @event

Returns:

Brick:

itself

on

(
  • eventName
  • listener
)
Brick chainable

Sets a listener on the Brick for a specified eventName.

Parameters:

  • eventName String

    an eventName to listen for

  • listener Function

    a callback function to be called

Returns:

Brick:

itself

setChoice

(
  • choiceKey
  • userSelected
)
ChoiceBrick chainable

Sets the choice of the ChoiceBrick.

Parameters:

  • choiceKey String

    string value of the choice to be selected

  • userSelected Boolean

    boolean value indicating if the user is the source of the selection

Returns:

ChoiceBrick:

itself

setData

(
  • data
)
ChoiceBrick chainable

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1216

Sets ChoiceBrick's data. First calls setChoice and calls set data on the Brick prototype.

Parameters:

  • data Object

    a wrapper object for the data to be set.

Returns:

ChoiceBrick:

itself

setState

(
  • state
)
Brick chainable

Sets the state of the Brick. Checks if the state being set is a freezing state and freezes/unfreezes the Brick.

Parameters:

  • state String

    a name of the state to set

Returns:

Brick:

itself

Properties

_isFrozen

Boolean private

Indicates if the Brick is frozen and cannot be interacted with.

Default: false

_listeners

Object private

A collection of listeners to be notified of specified Brick events.

Default: {}

baseTemplate

String private

A default base template name.

Default: "default_base_template"

choices

Array private

A collection of choices that will be offered to the user. At least two choices are required for this Brick to have any use at all.

Example:

[
    {
        key: "ie9",
        value: "IE9"
    },
    {
        key: "chrome",
        value: "Chrome"
    }
]

containerClass

String private

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1048

A CSS class of the MultiBrick container node.

Default: "choice-brick-container"

event

Object

A dictionary of possible Brick events.

Example:

 event: {
     CHANGE: "brick/change"
 }

freezeStates

Array private

A set of rules specifying states Brick should be frozen.

Default: []

Example:

 [
      Bricks.Brick.state.SUCCESS,
      Bricks.Brick.state.ERROR
  ],

header

String private

A Brick header.

Default: ""

instructions

String private

An instructional text to be displayed.

Default: ""

noticeTemplate

String private

A default notice template name.

Default: "default_brick_notice"

required

Array

A collection of rules specifying what external conditions must be valid for the Brick to be enabled. This is not used directly by the Brick itself, but instead by the external object manipulating a collection of Bricks. Two types of rules possible: "all" and "any". Any additional properties needed can be specified.

Default: null

Example:

 [
      {
          type: "all",
          check: ["serviceType", "serviceURL"]
      }
 ]

selectedChoice

String private

Indicates which choice is currently selected

Default: null

state

Object

A dictionary of Brick events.

Example:

state: {
  SUCCESS: "brick/success",
  ERROR: "brick/error",
  DEFAULT: "brick/default"
 }

template

String private

Inherited from Brick but overwritten in src/js/RAMP/Utils/bricks.js:1058

A name of the default ButtonBrick template.

Default: "default_choice_brick_template"

userSelected

Boolean private

Indicates if the user made the selection or it was made programmatically

Default: false

Events

Bricks.Brick.event.CHANGE

Published whenever a Brick undergoes some change.

Event Payload:

  • data Object

    anything, usually result of calling getData() on the Brick