1

Field Create Code

   $data = [
        'arguments' => [
            'data' => [
                'config' => [
                    'component' => 'vendor_module/js/form/element/ui-select-mixin',
                    'componentType' => Field::NAME,
                    'dataScope' => {data_scope},
                    'dataType' => Text::NAME,
                    'disableLabel' => true,
                    'elementTmpl' => 'ui/grid/filters/elements/ui-select',
                    'filterOptions' => true,
                    'formElement' => Select::NAME,
                    'label' => __('Label:'),
                    'multiple' => false,
                    'options' => $this->getOptions(),
                    'selectedPlaceholders' => [
                    'sortOrder' => $sortOrder,
                        'defaultPlaceholder' => __('None'),
                    ],
                    'validation' => [
                        'required-entry' => false
                    ]
                ],
            ],
        ],
    ];

Mixin Component Code

vendor_module/js/form/element/ui-select-mixin

define([
    'jquery',
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/ui-select',
    'uiLayout'
], function ($, _, registry, UiSelect) {
    'use strict';

    return UiSelect.extend({
        initialize: function () {
            //Some Lines of Code
            return this._super();
        }
    });
});

Field on Admin Form

enter image description here

So I am trying to access all the fields of that form in JS using uiRegistry. but when i print the field key in the console it is not there. Other fields key was printed like Checkbox, Text Area, Image. here is the code.

define([
    'uiElement',
    'uiRegistry'
], function (Element, registry) {
    'use strict';

    return Element.extend({

        initialize: function () {
            this._super();

            registry.filter(function(value, key) {
                console.log(key);
            });

            return this;
        },
    });
});

I want to get the value of all Select Field and Show at the particular Container. The above JS code is for Container Component.

If someone has a different way then also please comment.

Note: The Select Field is in Dyanamic Raw

2 Answers 2

0

Magento2 JS loads after the body is loaded. So whenever the page is loaded, the scripts are loaded simultaneously. You can try something like:

require(['jquery'],
    function ($){
        $(document).ready(function() {
            setTimeout(function(){
                  $('select[name="custom_attr_name"]').change(function () {
                      alert($(this).val());
                  });
              },5000);
    });
})

Or if it does not works try using body load inside the ready() function.

-2

List all components

var registry = require('uiRegistry');
registry.filter(function(value, key) {
    console.log(key);
    // console.log(value); 
});
1
  • Thanks for your answer. I did the same thing you can check on the question. Jan 10 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.