Skip to main content

Attribute

References​

  • The Attribute component is a dynamic utility for rendering and managing various types of attributes in UI.
  • It supports multiple attribute types like text, date, boolean, picklist, geolocation, etc.,
  • It provides methods for rendering, validating, and interacting with these attributes.

Key Properties:​

  1. renderValue(value, options): Renders the display value of the attribute.
  2. renderInput(value, onEdit, errorMessage, style, relatedInstanceId): Renders an input field for editing the attribute.
  3. validate(value, settings): Validates the attribute value.
  4. getAttributeValue(value): Retrieves the processed value of the attribute.
  5. getDefaultValues(timezone): Provides default values for the attribute.
  6. evaluateRuleCondition(condition, valueObj, compareToValueStr, secondValueStr, timeZone): Evaluates conditions for rule-based logic.

Usage Example:​

const { protrakComponents } = React.useContext(customWidgetContext);
const { Attribute } = protrakComponents;

const config = {
attributeName: "Name",
attributeType: "Text",
fieldType: "State",
customRenderer: null,
};

const attribute = Attribute(config);

// Render the attribute value
const renderedValue = attribute.renderValue("Sample Value");

// Render the input field for editing
const renderedInput = attribute.renderInput(
"Sample Value",
(newValue) => console.log("Edited Value:", newValue),
null,
{},
);

// Validate the attribute value
const validationError = attribute.validate("Sample Value");