Skip to main content

ConfigurableBooleanAttributeController

You get this controller when useAttribute(...) resolves a configurable boolean attribute. A boolean attribute is backed by value entities (typically an "on" and an "off" value); you select one by its cid.

import { useAttribute } from "@expivi/product-configurator";

const attribute = useAttribute(configurator, attributeCid);

Selecting a value

Pick the value entity you want and pass its cid to setValue(...). Pass null to clear the selection.

// Choose the "enabled" value entity
const enabled = attribute.allValues.find(v => v.config.value === "true");

if (enabled) {
attribute.setValue(enabled.cid);
}

// Clear the current selection
attribute.setValue(null);

API

This controller adds no new public members. Its type-specific behavior lives in the overridden setValue(...)/parse(...):

setValue(cid: string | null)

Selects the boolean value entity whose cid matches, storing its config.value as the configured value. Passing null (or an unknown cid) results in an empty selection.

attribute.setValue(booleanValueCid);

parse(data)

When parsing serialized data, the controller reads the first serialized value and selects the value entity whose config.value matches it. If no value matches, nothing is selected.

For all other members (data, values, subscribe(...), serialize(), reset(), and more), see the Common Attribute API.