Attribute
References
- The
Attributecomponent 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:
renderValue(value, options): Renders the display value of the attribute.renderInput(value, onEdit, errorMessage, style, relatedInstanceId): Renders an input field for editing the attribute.validate(value, settings): Validates the attribute value.getAttributeValue(value): Retrieves the processed value of the attribute.getDefaultValues(timezone): Provides default values for the attribute.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');