Skip to content

valuesSubstore

Manages the selected option values and quantities for every configuration. Each config has its own isolated ValuesStoreItem, stored in valuesConfigs. The form constraint engine reads from this substore to evaluate which elements/options should be shown or hidden.

Table of contents

Properties

Methods


Properties

valuesConfigs

valuesConfigs: Record<number, ValuesStoreItemVariables>

Map from config ID to its values, quantities, and selected-products state.

Each entry holds:

  • values: TValuesRecord<elementId, string[]> of selected option IDs or free-text values
  • quantities: TQuantitiesRecord<elementId, Record<optionId, number>> of option quantities
  • selectedProductsIds: Set<number> — IDs of products linked to selected options
  • selectedProductsQuantities: Record<number, number> — product quantities

Entries are created by configsSubstore.addConfig and removed by configsSubstore.removeConfig.

type TValues = Record<string, string[]>;
type TQuantities = Record<string, Record<string, number>>;

Related


Methods

setElementValue

setElementValue: (
configId: number,
elementId: number,
value: string[],
) => void

Sets the selected values for a specific element in a config.

Replaces the entire value array for elementId. Pass an empty array to deselect all options. The constraint engine re-evaluates automatically after this call.

Parameters

NameTypeDescription
configIdnumberTarget configuration
elementIdnumberTarget element
valuestring[]Array of selected option IDs or free-text values

Related


setOptionQuantity

setOptionQuantity: (
configId: number,
elementId: number,
optionId: number,
quantity: number,
) => void

Sets the quantity of a specific option within an element for the given config.

Does not affect whether the option is selected — selection is managed via setElementValue.

Parameters

NameTypeDescription
configIdnumberTarget configuration
elementIdnumberElement containing the option
optionIdnumberOption whose quantity to set
quantitynumberNew quantity value

Related


setValues

setValues: (configId: number, values: TValues) => void

Bulk-replaces all values for the given config.

Replaces the entire values map for configId. Use this when restoring state (e.g., from a draft) rather than setting values one element at a time.

Parameters

NameTypeDescription
configIdnumberTarget configuration
valuesTValuesComplete values map (Record<elementId, string[]>)

Related


setQuantities

setQuantities: (configId: number, quantities: TQuantities) => void

Bulk-replaces all quantities for the given config.

Replaces the entire quantities map for configId. Use alongside setValues when restoring full config state.

Parameters

NameTypeDescription
configIdnumberTarget configuration
quantitiesTQuantitiesComplete quantities map (Record<elementId, Record<optionId, number>>)

Related


handleChangeInput

handleChangeInput: (args: {
configId: number;
type: TElement["type"];
elementId: number;
optionIdOrValue: string | number;
}) => void

Handles a user input event — toggles a checkbox option or sets a single value depending on element type.

This is the recommended method for wiring up UI input handlers. It implements the correct selection logic for each element type:

  • Checkbox elements: toggles the option in the current values array (adds if absent, removes if present)
  • All other types (radio, select, text, …): replaces the current selection with [optionIdOrValue]

Parameters

NameTypeDescription
args.configIdnumberTarget configuration
args.typeTElement["type"]Element type — controls toggle vs replace behaviour
args.elementIdnumberTarget element
args.optionIdOrValuestring | numberOption ID (for option-based elements) or free-text value

Related