Library iblock.field-selector
Description and example
Library iblock.field-selector is designed to be used in custom properties for iblock and binding UF-fields for Information blocks module entities.
Library allows using TagSelector in the form or grid input fields. The values be integers or strings.
Use:
\Bitrix\Main\Loader::includeModule('iblock'); \Bitrix\Main\UI\Extension::load('iblock.field-selector'); $containerId = 'my_element'; // container's ID dom for TagSelector $values = 100; // current value $config = \Bitrix\Main\Web\Json::encode([ 'containerId' => $containerId, 'fieldName' => 'myfield', 'multiple' => false, 'collectionType' => 'int', 'selectedItems' => $values, 'iblockId' => 41, 'userType' => \Bitrix\Iblock\PropertyTable::USER_TYPE_ELEMENT_AUTOCOMPLETE, 'entityId' => \Bitrix\Iblock\Integration\UI\EntitySelector\IblockPropertyElementProvider::ENTITY_ID, ]); return <<<HTML <div id="$containerId"></div> <script> (function() { const selector = new BX.Iblock.FieldSelector($config); selector.render(); })(); </script> HTML;
The example above has a set of items, belonging to iblock with ID = 41 for single (multiple) "Link-to-element autocomplete text box" (userType) property type. Current value (selectedItems) – 100. Value type is passed in the key collectionType and can have values int
or string
.
Data provider ID is specified in the key entityId.
Attention! You can work only with a single provider at a time. This is due to specified of library design.
DOM-element for selector container must be rendered manually.
Input parameters
Parameter | Type | Description |
---|---|---|
containerId * | string | Page DOM-element, containing selector. |
fieldName * | string | Form field name to record the result. You must add [] to field name for selector with multiple selection. |
multiple | bool | Singular or multiple property/field. Default value: false . |
collectionType | string | Property/field property type. Possible values – int or string . Default value: int .
Attention! Current values for selector must be converted to this type. |
selectedItems * |
| Current values for property/field. |
iblockId * | int | Iblock ID from which data is fetched. If property/field is not associated to a specific iblock, you must pass null. |
userType | string | Custom property/field ID. |
entityId * | string | Data provider ID. Standard providers are available:
|
searchMessages | object | Search window messages in case of empty result. Object contains fields:
|
changeEvents | arrays | List with js events, called after value updates in selector. |
* – required parameters.