uiRegistry library
uiRegistry
is in-memory, plain storage of entities by keys. Implements the get()
, set()
, and has()
methods.
JavaScript debugging
To debug the UI component JS, we first need to get a uiRegistry
instance from the browser console. To do so, use the RequireJs ID uiRegistry
.
In the browser console enter the following:
Copied to your clipboardvar registry = require('uiRegistry');
Now we have uiRegistry
instance in the registry
variable. We can use it to get an instance of any component.
Copied to your clipboardvar component = registry.get('componentName');
The uiRegistry
instance allows you to search for components using property values.
If you know a unique property value of a component that you need to find, you can use the following code to get the component:
Copied to your clipboardvar component = registry.get('property = propertyValue');
To get a list of all components used on the current page, you can use this code:
Copied to your clipboardrequire('uiRegistry').get(function(component){console.log(component.name)});
Asynchronously retrieve components from the registry
This is the recommended method for best performance.
Copied to your clipboardmodule('trigger', true);var component = () => registry.get('componentName', function (component) {component.trigger(true);});
Examples:
The following code shows how to get a component by a full component name:
Copied to your clipboard// Admin > Products > Catalog > Add Productvar fieldName = registry.get('product_form.product_form.product-details.container_name.name');
The following code shows how to get a component by a property value:
Copied to your clipboard// Admin > Products > Catalog > Add Productvar fieldName = registry.get('index = name');// orfieldName = registry.get('inputName = product[name]');
The previous example gets the same JS component as using the full component name.
Lets look what we have in component variable. It keeps component context with all properties, we can see component file, component name and so on.
Copied to your clipboardconsole.log(fieldName.name); // product_form.product_form.product-details.container_name.namefieldName.trigger('validate'); // will invoke validationfieldName.visible(false); // will hide field from pagefieldName.visible(true); // will show field againfieldName.value(); // will show current field valuefieldName.value('New string value'); // will change field value to string 'New string value'