Selectors
Selectors
Selectors are a hypermedia control that change a resource's state. Selectors provide a list of predefined options that a shopper can choose from. Once a choice is made through the selector, the resource's state updates accordingly. Selectors are generally rendered on the UI as radio button groups, combo boxes, or check boxes.
- The options available for a resource.
- The options already selected for a resource.
- The selection-rule that determines how many options can be selected at once.
- The links to make the selection.
-
A name property that identifies which options the selector handles.
-
A selection-rule property that identifies the number of options that can be selected at once.
-
A choice link for options that can be selected.
-
A chosen link for options that are already selected.
-
A description link that links to a description of the option.
-
A selectaction link that when followed selects the option. The link appears only on choice resources as chosen resources are already selected.
Selector Example: Selecting a Billing Address
{ "rel": "selector", "rev": "billingaddressinfo", "type": "elasticpath.controls.selector", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector" }
{ "self": { "type": "elasticpath.controls.selector", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector", "max-age": 0 }, "name": "billing-address-selector", "selection-rule": "1", "links": [ { "rel": "choice", "rev": "selector", "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=" }, { "rel": "choice", "rev": "selector", "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ha4=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ha4=" }, { "rel": "billingaddressinfo", "rev": "selector", "type": "elasticpath.controls.info", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo" } ] }}
{ "self": { "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "max-age": 0 }, "links": [ { "rel": "description", "type": "elasticpath.addresses.address", "uri": "/commerce-legacy/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/profiles/mobee/grd=/addresses/ga3=" }, { "rel": "selectaction", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=" }, { "rel": "selector", "type": "elasticpath.controls.selector", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector" } ] }
POST /orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3= Content-Type: application/json
200 OK Location: http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector
{ "self": { "type": "elasticpath.controls.selector", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector", "max-age": 0 }, "name": "billing-address-selector", "selection-rule": "1", "links": [ { "rel": "choice", "rev": "selector", "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ha4=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ha4=" }, { "rel": "chosen", "rev": "selector", "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=" } { "rel": "billingaddressinfo", "rev": "selector", "type": "elasticpath.controls.info", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo" } ] }
The chosen resource does not have a selectaction link because it is already selected:
{ "self": { "type": "elasticpath.collections.links", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector/profiles/mobee/grd=/addresses/ga3=", "max-age": 0 }, "links": [ { "rel": "description", "type": "elasticpath.addresses.address", "uri": "/commerce-legacy/profiles/mobee/grd=/addresses/ga3=", "href": "http://api.elasticpath.net/cortex/profiles/mobee/grd=/addresses/ga3=" } { "rel": "selector", "type": "elasticpath.controls.selector", "uri": "/commerce-legacy/orders/mobee/mu3=/billingaddressinfo/selector", "href": "http://api.elasticpath.net/cortex/orders/mobee/mu3=/billingaddressinfo/selector" } ] }