Magento 2 : Run/Execute Javascript after KnockoutJS has rendered all elementsPageSpeed JavaScript LoadingHow can I trigger code to run after knockoutjs render in adminhtmlHow to create autocomplete for city field(checkout form) Magento2?Checkout uiComponent (input field) rendered multiple times: how do I apply viewmodel functionality to current input field only?Magento 2 - Load custom javascript with requirejsMagento 2: What is the proper format for a javascript widget's _bind() method?Force page rendering after new HTML is loaded by AJAXRun JavaScript after data-mage-init / mage.apply() has finished loadingMagento 2 Run/Execute jquery after KnockoutJS has rendered all elementsMagento 2. Describe different types and uses of JavaScript modules. Which JavaScript modules are suited for which tasks?

Why does aggregate initialization not work anymore since C++20 if a constructor is explicitly defaulted or deleted?

Is it possible for a particle to decay via gravity?

GNU GPL V3 with no code change disclosure

Can Lightning Lure be used to knock out a creature like a magical Taser?

Why tantalum for the Hayabusa bullets?

Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?

Alternatives to minimizing loss in regression

What force enables us to walk? Friction or normal reaction?

Why is it "on the inside" and not "in the inside"?

Is SecureRandom.ints() secure?

Does Ubuntu reduces battery life?

Little Lost Robot

How to innovate in OR

Is it safe if the neutral lead is exposed and disconnected?

Can Papyrus be folded?

Does dual boot harm a laptop battery or reduce its life?

Why are we moving in circles with a tandem kayak?

Self-deportation of American Citizens from US

Should I intervene when a colleague in a different department makes students run laps as part of their grade?

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

Semen retention is a important thing in Martial arts?

How did the SysRq key get onto modern keyboards if it's rarely used?

Who said "one can be a powerful king with a very small sceptre"?

How should I quote American English speakers in a British English essay?



Magento 2 : Run/Execute Javascript after KnockoutJS has rendered all elements


PageSpeed JavaScript LoadingHow can I trigger code to run after knockoutjs render in adminhtmlHow to create autocomplete for city field(checkout form) Magento2?Checkout uiComponent (input field) rendered multiple times: how do I apply viewmodel functionality to current input field only?Magento 2 - Load custom javascript with requirejsMagento 2: What is the proper format for a javascript widget's _bind() method?Force page rendering after new HTML is loaded by AJAXRun JavaScript after data-mage-init / mage.apply() has finished loadingMagento 2 Run/Execute jquery after KnockoutJS has rendered all elementsMagento 2. Describe different types and uses of JavaScript modules. Which JavaScript modules are suited for which tasks?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















I am trying to run custom Javascript code after the page is loaded completely with all the form elements/fields.



I am trying this on Magento2 Admin while adding new product.




For example:



I am trying to disable Quantity field in New Product add page in
Magento2 Admin.




The page content is rendered through KnockoutJS. So, the following jQuery on load are not working:



jQuery(window).bind("load", function() 
// your code
);

// OR

jQuery(window).on('load', function()
// your code
);


How to run Javascript code in Magento 2 after KnockoutJS has completed rendering all the DOM elements?










share|improve this question
























  • You can check link, rakeshjesadiya.com/…

    – Rakesh Jesadiya
    Nov 18 '18 at 14:26

















7















I am trying to run custom Javascript code after the page is loaded completely with all the form elements/fields.



I am trying this on Magento2 Admin while adding new product.




For example:



I am trying to disable Quantity field in New Product add page in
Magento2 Admin.




The page content is rendered through KnockoutJS. So, the following jQuery on load are not working:



jQuery(window).bind("load", function() 
// your code
);

// OR

jQuery(window).on('load', function()
// your code
);


How to run Javascript code in Magento 2 after KnockoutJS has completed rendering all the DOM elements?










share|improve this question
























  • You can check link, rakeshjesadiya.com/…

    – Rakesh Jesadiya
    Nov 18 '18 at 14:26













7












7








7


4






I am trying to run custom Javascript code after the page is loaded completely with all the form elements/fields.



I am trying this on Magento2 Admin while adding new product.




For example:



I am trying to disable Quantity field in New Product add page in
Magento2 Admin.




The page content is rendered through KnockoutJS. So, the following jQuery on load are not working:



jQuery(window).bind("load", function() 
// your code
);

// OR

jQuery(window).on('load', function()
// your code
);


How to run Javascript code in Magento 2 after KnockoutJS has completed rendering all the DOM elements?










share|improve this question














I am trying to run custom Javascript code after the page is loaded completely with all the form elements/fields.



I am trying this on Magento2 Admin while adding new product.




For example:



I am trying to disable Quantity field in New Product add page in
Magento2 Admin.




The page content is rendered through KnockoutJS. So, the following jQuery on load are not working:



jQuery(window).bind("load", function() 
// your code
);

// OR

jQuery(window).on('load', function()
// your code
);


How to run Javascript code in Magento 2 after KnockoutJS has completed rendering all the DOM elements?







magento2 javascript knockoutjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 12 '17 at 11:35









Mukesh ChapagainMukesh Chapagain

4,0362 gold badges23 silver badges45 bronze badges




4,0362 gold badges23 silver badges45 bronze badges















  • You can check link, rakeshjesadiya.com/…

    – Rakesh Jesadiya
    Nov 18 '18 at 14:26

















  • You can check link, rakeshjesadiya.com/…

    – Rakesh Jesadiya
    Nov 18 '18 at 14:26
















You can check link, rakeshjesadiya.com/…

– Rakesh Jesadiya
Nov 18 '18 at 14:26





You can check link, rakeshjesadiya.com/…

– Rakesh Jesadiya
Nov 18 '18 at 14:26










4 Answers
4






active

oldest

votes


















9














Because Magento use async rendering it not possible to make what you ask.



But you can work with js UI component to disable field



require(['uiRegistry'], function (uiRegistry) 
uiRegistry.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (element)
element.disable()
)
)


This answer is correct, however we're lacking information regarding how we know to use 'product_form.product_form.product-details.quanityt_and_stock_status_qty.qty' as the get() parameter.



.get is looking for its first parameter to be a component. So... how do you find the component, and is that language clear? No.



As an example, I wanted to add some custom javascript functionality to the customer information page within the Magento 2 admin. Specifically under, editing a user, 'Account Information' tab.



There are two ways to approach this from what I can tell...



Edit the datasource, to change values.
Manipulate the field, such as visibility.



Edit the datasource:



Lets roll. Some dots are missing here, but we're on a page handled by the magento customer module, its an edit page... so we look here... /vendor/module-customer/view/adminhtml/layout/customer_index_edit.xml. Within here the content area is defined to contain 'customer_form'.



<referenceContainer name="content">
<uiComponent name="customer_form"/>
</referenceContainer>


This means we're looking for a 'customer_form.xml' file, in this case it is found under /vendor/module-customer/view/base/ui_component/customer_form.xml. Within here we find the definition for a couple of the forms within the tabs and their fields. The datasource we're after is defined near the top.



<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Customer Information</item>
<item name="reverseMetadataMerge" xsi:type="boolean">true</item>
</argument>


Note the 'provider' of 'customer_form.customer_form_data_source'. This is where all of our field data will exist within the .get call.



Our .get() would now become:



uiRegistry.get('customer_form.customer_form_data_source', function(element) 
console.log(element.data);
);


Now, the question becomes... what can we do with this- and all you can do is adjust the data. You can turn fields true/false, manipulate values, so on. Useful.



Manipulate the field:



What if we want to hide the field and only show it under x condition... we can't do that with the datasource.



Now... this is going to be long and seem convoluted. Its because I'm teaching how to find your data... as I don't know how to find this any other way- and its going to be different per module. Teach a man to fish.



First I output my 'customer_form.customer_form_data_source' within our .get(). This will provide us a 'params' object key, within that is the definition of an 'activeArea' on the object, which is 'customer_form.areas.customer_edit_tab_view_content'.



Ok... so there are 'areas'. Areas, are the tabs on the left- each one is an area. Open up the '_elems' within your console, you'll notice 9 objects at the top. Open the second one and you'll find a label of 'Account Information'. This is the section I'm after. Then observe the 'name' value of 'customer_form.areas.customer'... ok lets try that as our get() param.



uiRegistry.get('customer_form.areas.customer', function(element) 
console.log(element);
);


This is our fieldset wrapper, check its name value within the console under '_elems'->0->'name'. 'customer_form.areas.customer.customer'... we're drilling down. We're actually already there, check the 'name' value on the field you want to edit. You'll notice its name is 'customer[field_name]'. Making our path for get() is 'customer_form.areas.customer.customer.['field_name]'.



uiRegistry.get('customer_form.areas.customer.customer.[field_name]', function(element) 
element.visible(false);
);


Examples:
[form_name].[tab_areas].[area_name].[fieldset_name].[field_name]
customer_form.areas.customer.customer.field_name






share|improve this answer



























  • Can you please explain how to get identifier for a field in ui component?

    – Vivek Kumar
    Jan 18 '18 at 8:15











  • You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

    – Daan van den Bergh
    Jun 21 '18 at 12:37


















5














There is a plugin built into Require JS to handle page load, this is the preferred method as any other modules that depend on yours will also be aware of the page load requirement. If you use the jQuery method mentioned by Rajeev the other modules will not be aware of the page load requirement.



The plugin is called domReady! and can be used by adding it as a dependency like so:



require(["jquery", "domReady!"], function($)
// Your code here
);


This will wait for page load but doesn't necessarily mean it loads after all other KO modules as they may also be waiting for page load. For that reason I think KAndy's method is the most reliable, but this answer may help others.






share|improve this answer
































    0














    You can try something like this.



    <script type="text/javascript">
    require(["jquery"], function($)
    $(function()

    //do your stuff here

    );
    );
    </script>


    This will make sure, your code will get executed only after dom is fully loaded. If you are familiar with jquery, you will be probably know what $(function() ); does. It makes sure code comes inside that anonymous function will get executed only after DOM is completely loaded.






    share|improve this answer




















    • 1





      Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

      – Mukesh Chapagain
      Feb 12 '17 at 16:38



















    0














    The document ready or DOM loaded events won't be fired on completion of UI form loading.



    Here, either you shall have to write a function in javascript which should be called at some interval and as soon as your target element appears in DOM, process your business logic and clear the interval.



    Another option could be - to execute your JavaScript business logic after completion of AJAX request which can be achieved using following code block.



    $(document).ajaxComplete(function() 
    // enter your code here
    );





    share|improve this answer



























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159427%2fmagento-2-run-execute-javascript-after-knockoutjs-has-rendered-all-elements%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9














      Because Magento use async rendering it not possible to make what you ask.



      But you can work with js UI component to disable field



      require(['uiRegistry'], function (uiRegistry) 
      uiRegistry.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (element)
      element.disable()
      )
      )


      This answer is correct, however we're lacking information regarding how we know to use 'product_form.product_form.product-details.quanityt_and_stock_status_qty.qty' as the get() parameter.



      .get is looking for its first parameter to be a component. So... how do you find the component, and is that language clear? No.



      As an example, I wanted to add some custom javascript functionality to the customer information page within the Magento 2 admin. Specifically under, editing a user, 'Account Information' tab.



      There are two ways to approach this from what I can tell...



      Edit the datasource, to change values.
      Manipulate the field, such as visibility.



      Edit the datasource:



      Lets roll. Some dots are missing here, but we're on a page handled by the magento customer module, its an edit page... so we look here... /vendor/module-customer/view/adminhtml/layout/customer_index_edit.xml. Within here the content area is defined to contain 'customer_form'.



      <referenceContainer name="content">
      <uiComponent name="customer_form"/>
      </referenceContainer>


      This means we're looking for a 'customer_form.xml' file, in this case it is found under /vendor/module-customer/view/base/ui_component/customer_form.xml. Within here we find the definition for a couple of the forms within the tabs and their fields. The datasource we're after is defined near the top.



      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
      </item>
      <item name="label" xsi:type="string" translate="true">Customer Information</item>
      <item name="reverseMetadataMerge" xsi:type="boolean">true</item>
      </argument>


      Note the 'provider' of 'customer_form.customer_form_data_source'. This is where all of our field data will exist within the .get call.



      Our .get() would now become:



      uiRegistry.get('customer_form.customer_form_data_source', function(element) 
      console.log(element.data);
      );


      Now, the question becomes... what can we do with this- and all you can do is adjust the data. You can turn fields true/false, manipulate values, so on. Useful.



      Manipulate the field:



      What if we want to hide the field and only show it under x condition... we can't do that with the datasource.



      Now... this is going to be long and seem convoluted. Its because I'm teaching how to find your data... as I don't know how to find this any other way- and its going to be different per module. Teach a man to fish.



      First I output my 'customer_form.customer_form_data_source' within our .get(). This will provide us a 'params' object key, within that is the definition of an 'activeArea' on the object, which is 'customer_form.areas.customer_edit_tab_view_content'.



      Ok... so there are 'areas'. Areas, are the tabs on the left- each one is an area. Open up the '_elems' within your console, you'll notice 9 objects at the top. Open the second one and you'll find a label of 'Account Information'. This is the section I'm after. Then observe the 'name' value of 'customer_form.areas.customer'... ok lets try that as our get() param.



      uiRegistry.get('customer_form.areas.customer', function(element) 
      console.log(element);
      );


      This is our fieldset wrapper, check its name value within the console under '_elems'->0->'name'. 'customer_form.areas.customer.customer'... we're drilling down. We're actually already there, check the 'name' value on the field you want to edit. You'll notice its name is 'customer[field_name]'. Making our path for get() is 'customer_form.areas.customer.customer.['field_name]'.



      uiRegistry.get('customer_form.areas.customer.customer.[field_name]', function(element) 
      element.visible(false);
      );


      Examples:
      [form_name].[tab_areas].[area_name].[fieldset_name].[field_name]
      customer_form.areas.customer.customer.field_name






      share|improve this answer



























      • Can you please explain how to get identifier for a field in ui component?

        – Vivek Kumar
        Jan 18 '18 at 8:15











      • You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

        – Daan van den Bergh
        Jun 21 '18 at 12:37















      9














      Because Magento use async rendering it not possible to make what you ask.



      But you can work with js UI component to disable field



      require(['uiRegistry'], function (uiRegistry) 
      uiRegistry.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (element)
      element.disable()
      )
      )


      This answer is correct, however we're lacking information regarding how we know to use 'product_form.product_form.product-details.quanityt_and_stock_status_qty.qty' as the get() parameter.



      .get is looking for its first parameter to be a component. So... how do you find the component, and is that language clear? No.



      As an example, I wanted to add some custom javascript functionality to the customer information page within the Magento 2 admin. Specifically under, editing a user, 'Account Information' tab.



      There are two ways to approach this from what I can tell...



      Edit the datasource, to change values.
      Manipulate the field, such as visibility.



      Edit the datasource:



      Lets roll. Some dots are missing here, but we're on a page handled by the magento customer module, its an edit page... so we look here... /vendor/module-customer/view/adminhtml/layout/customer_index_edit.xml. Within here the content area is defined to contain 'customer_form'.



      <referenceContainer name="content">
      <uiComponent name="customer_form"/>
      </referenceContainer>


      This means we're looking for a 'customer_form.xml' file, in this case it is found under /vendor/module-customer/view/base/ui_component/customer_form.xml. Within here we find the definition for a couple of the forms within the tabs and their fields. The datasource we're after is defined near the top.



      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
      </item>
      <item name="label" xsi:type="string" translate="true">Customer Information</item>
      <item name="reverseMetadataMerge" xsi:type="boolean">true</item>
      </argument>


      Note the 'provider' of 'customer_form.customer_form_data_source'. This is where all of our field data will exist within the .get call.



      Our .get() would now become:



      uiRegistry.get('customer_form.customer_form_data_source', function(element) 
      console.log(element.data);
      );


      Now, the question becomes... what can we do with this- and all you can do is adjust the data. You can turn fields true/false, manipulate values, so on. Useful.



      Manipulate the field:



      What if we want to hide the field and only show it under x condition... we can't do that with the datasource.



      Now... this is going to be long and seem convoluted. Its because I'm teaching how to find your data... as I don't know how to find this any other way- and its going to be different per module. Teach a man to fish.



      First I output my 'customer_form.customer_form_data_source' within our .get(). This will provide us a 'params' object key, within that is the definition of an 'activeArea' on the object, which is 'customer_form.areas.customer_edit_tab_view_content'.



      Ok... so there are 'areas'. Areas, are the tabs on the left- each one is an area. Open up the '_elems' within your console, you'll notice 9 objects at the top. Open the second one and you'll find a label of 'Account Information'. This is the section I'm after. Then observe the 'name' value of 'customer_form.areas.customer'... ok lets try that as our get() param.



      uiRegistry.get('customer_form.areas.customer', function(element) 
      console.log(element);
      );


      This is our fieldset wrapper, check its name value within the console under '_elems'->0->'name'. 'customer_form.areas.customer.customer'... we're drilling down. We're actually already there, check the 'name' value on the field you want to edit. You'll notice its name is 'customer[field_name]'. Making our path for get() is 'customer_form.areas.customer.customer.['field_name]'.



      uiRegistry.get('customer_form.areas.customer.customer.[field_name]', function(element) 
      element.visible(false);
      );


      Examples:
      [form_name].[tab_areas].[area_name].[fieldset_name].[field_name]
      customer_form.areas.customer.customer.field_name






      share|improve this answer



























      • Can you please explain how to get identifier for a field in ui component?

        – Vivek Kumar
        Jan 18 '18 at 8:15











      • You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

        – Daan van den Bergh
        Jun 21 '18 at 12:37













      9












      9








      9







      Because Magento use async rendering it not possible to make what you ask.



      But you can work with js UI component to disable field



      require(['uiRegistry'], function (uiRegistry) 
      uiRegistry.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (element)
      element.disable()
      )
      )


      This answer is correct, however we're lacking information regarding how we know to use 'product_form.product_form.product-details.quanityt_and_stock_status_qty.qty' as the get() parameter.



      .get is looking for its first parameter to be a component. So... how do you find the component, and is that language clear? No.



      As an example, I wanted to add some custom javascript functionality to the customer information page within the Magento 2 admin. Specifically under, editing a user, 'Account Information' tab.



      There are two ways to approach this from what I can tell...



      Edit the datasource, to change values.
      Manipulate the field, such as visibility.



      Edit the datasource:



      Lets roll. Some dots are missing here, but we're on a page handled by the magento customer module, its an edit page... so we look here... /vendor/module-customer/view/adminhtml/layout/customer_index_edit.xml. Within here the content area is defined to contain 'customer_form'.



      <referenceContainer name="content">
      <uiComponent name="customer_form"/>
      </referenceContainer>


      This means we're looking for a 'customer_form.xml' file, in this case it is found under /vendor/module-customer/view/base/ui_component/customer_form.xml. Within here we find the definition for a couple of the forms within the tabs and their fields. The datasource we're after is defined near the top.



      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
      </item>
      <item name="label" xsi:type="string" translate="true">Customer Information</item>
      <item name="reverseMetadataMerge" xsi:type="boolean">true</item>
      </argument>


      Note the 'provider' of 'customer_form.customer_form_data_source'. This is where all of our field data will exist within the .get call.



      Our .get() would now become:



      uiRegistry.get('customer_form.customer_form_data_source', function(element) 
      console.log(element.data);
      );


      Now, the question becomes... what can we do with this- and all you can do is adjust the data. You can turn fields true/false, manipulate values, so on. Useful.



      Manipulate the field:



      What if we want to hide the field and only show it under x condition... we can't do that with the datasource.



      Now... this is going to be long and seem convoluted. Its because I'm teaching how to find your data... as I don't know how to find this any other way- and its going to be different per module. Teach a man to fish.



      First I output my 'customer_form.customer_form_data_source' within our .get(). This will provide us a 'params' object key, within that is the definition of an 'activeArea' on the object, which is 'customer_form.areas.customer_edit_tab_view_content'.



      Ok... so there are 'areas'. Areas, are the tabs on the left- each one is an area. Open up the '_elems' within your console, you'll notice 9 objects at the top. Open the second one and you'll find a label of 'Account Information'. This is the section I'm after. Then observe the 'name' value of 'customer_form.areas.customer'... ok lets try that as our get() param.



      uiRegistry.get('customer_form.areas.customer', function(element) 
      console.log(element);
      );


      This is our fieldset wrapper, check its name value within the console under '_elems'->0->'name'. 'customer_form.areas.customer.customer'... we're drilling down. We're actually already there, check the 'name' value on the field you want to edit. You'll notice its name is 'customer[field_name]'. Making our path for get() is 'customer_form.areas.customer.customer.['field_name]'.



      uiRegistry.get('customer_form.areas.customer.customer.[field_name]', function(element) 
      element.visible(false);
      );


      Examples:
      [form_name].[tab_areas].[area_name].[fieldset_name].[field_name]
      customer_form.areas.customer.customer.field_name






      share|improve this answer















      Because Magento use async rendering it not possible to make what you ask.



      But you can work with js UI component to disable field



      require(['uiRegistry'], function (uiRegistry) 
      uiRegistry.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (element)
      element.disable()
      )
      )


      This answer is correct, however we're lacking information regarding how we know to use 'product_form.product_form.product-details.quanityt_and_stock_status_qty.qty' as the get() parameter.



      .get is looking for its first parameter to be a component. So... how do you find the component, and is that language clear? No.



      As an example, I wanted to add some custom javascript functionality to the customer information page within the Magento 2 admin. Specifically under, editing a user, 'Account Information' tab.



      There are two ways to approach this from what I can tell...



      Edit the datasource, to change values.
      Manipulate the field, such as visibility.



      Edit the datasource:



      Lets roll. Some dots are missing here, but we're on a page handled by the magento customer module, its an edit page... so we look here... /vendor/module-customer/view/adminhtml/layout/customer_index_edit.xml. Within here the content area is defined to contain 'customer_form'.



      <referenceContainer name="content">
      <uiComponent name="customer_form"/>
      </referenceContainer>


      This means we're looking for a 'customer_form.xml' file, in this case it is found under /vendor/module-customer/view/base/ui_component/customer_form.xml. Within here we find the definition for a couple of the forms within the tabs and their fields. The datasource we're after is defined near the top.



      <argument name="data" xsi:type="array">
      <item name="js_config" xsi:type="array">
      <item name="provider" xsi:type="string">customer_form.customer_form_data_source</item>
      </item>
      <item name="label" xsi:type="string" translate="true">Customer Information</item>
      <item name="reverseMetadataMerge" xsi:type="boolean">true</item>
      </argument>


      Note the 'provider' of 'customer_form.customer_form_data_source'. This is where all of our field data will exist within the .get call.



      Our .get() would now become:



      uiRegistry.get('customer_form.customer_form_data_source', function(element) 
      console.log(element.data);
      );


      Now, the question becomes... what can we do with this- and all you can do is adjust the data. You can turn fields true/false, manipulate values, so on. Useful.



      Manipulate the field:



      What if we want to hide the field and only show it under x condition... we can't do that with the datasource.



      Now... this is going to be long and seem convoluted. Its because I'm teaching how to find your data... as I don't know how to find this any other way- and its going to be different per module. Teach a man to fish.



      First I output my 'customer_form.customer_form_data_source' within our .get(). This will provide us a 'params' object key, within that is the definition of an 'activeArea' on the object, which is 'customer_form.areas.customer_edit_tab_view_content'.



      Ok... so there are 'areas'. Areas, are the tabs on the left- each one is an area. Open up the '_elems' within your console, you'll notice 9 objects at the top. Open the second one and you'll find a label of 'Account Information'. This is the section I'm after. Then observe the 'name' value of 'customer_form.areas.customer'... ok lets try that as our get() param.



      uiRegistry.get('customer_form.areas.customer', function(element) 
      console.log(element);
      );


      This is our fieldset wrapper, check its name value within the console under '_elems'->0->'name'. 'customer_form.areas.customer.customer'... we're drilling down. We're actually already there, check the 'name' value on the field you want to edit. You'll notice its name is 'customer[field_name]'. Making our path for get() is 'customer_form.areas.customer.customer.['field_name]'.



      uiRegistry.get('customer_form.areas.customer.customer.[field_name]', function(element) 
      element.visible(false);
      );


      Examples:
      [form_name].[tab_areas].[area_name].[fieldset_name].[field_name]
      customer_form.areas.customer.customer.field_name







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 1 '18 at 13:57









      KazaJhodo

      731 silver badge3 bronze badges




      731 silver badge3 bronze badges










      answered Feb 12 '17 at 13:45









      KAndyKAndy

      16.6k2 gold badges36 silver badges47 bronze badges




      16.6k2 gold badges36 silver badges47 bronze badges















      • Can you please explain how to get identifier for a field in ui component?

        – Vivek Kumar
        Jan 18 '18 at 8:15











      • You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

        – Daan van den Bergh
        Jun 21 '18 at 12:37

















      • Can you please explain how to get identifier for a field in ui component?

        – Vivek Kumar
        Jan 18 '18 at 8:15











      • You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

        – Daan van den Bergh
        Jun 21 '18 at 12:37
















      Can you please explain how to get identifier for a field in ui component?

      – Vivek Kumar
      Jan 18 '18 at 8:15





      Can you please explain how to get identifier for a field in ui component?

      – Vivek Kumar
      Jan 18 '18 at 8:15













      You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

      – Daan van den Bergh
      Jun 21 '18 at 12:37





      You can find registry-names of any KnockoutJS elements easily using the following Google Chrome-extension: Knockoutjs context debugger. Just click on the element you want to know the name of and find the 'name'-element inside the output.

      – Daan van den Bergh
      Jun 21 '18 at 12:37













      5














      There is a plugin built into Require JS to handle page load, this is the preferred method as any other modules that depend on yours will also be aware of the page load requirement. If you use the jQuery method mentioned by Rajeev the other modules will not be aware of the page load requirement.



      The plugin is called domReady! and can be used by adding it as a dependency like so:



      require(["jquery", "domReady!"], function($)
      // Your code here
      );


      This will wait for page load but doesn't necessarily mean it loads after all other KO modules as they may also be waiting for page load. For that reason I think KAndy's method is the most reliable, but this answer may help others.






      share|improve this answer





























        5














        There is a plugin built into Require JS to handle page load, this is the preferred method as any other modules that depend on yours will also be aware of the page load requirement. If you use the jQuery method mentioned by Rajeev the other modules will not be aware of the page load requirement.



        The plugin is called domReady! and can be used by adding it as a dependency like so:



        require(["jquery", "domReady!"], function($)
        // Your code here
        );


        This will wait for page load but doesn't necessarily mean it loads after all other KO modules as they may also be waiting for page load. For that reason I think KAndy's method is the most reliable, but this answer may help others.






        share|improve this answer



























          5












          5








          5







          There is a plugin built into Require JS to handle page load, this is the preferred method as any other modules that depend on yours will also be aware of the page load requirement. If you use the jQuery method mentioned by Rajeev the other modules will not be aware of the page load requirement.



          The plugin is called domReady! and can be used by adding it as a dependency like so:



          require(["jquery", "domReady!"], function($)
          // Your code here
          );


          This will wait for page load but doesn't necessarily mean it loads after all other KO modules as they may also be waiting for page load. For that reason I think KAndy's method is the most reliable, but this answer may help others.






          share|improve this answer













          There is a plugin built into Require JS to handle page load, this is the preferred method as any other modules that depend on yours will also be aware of the page load requirement. If you use the jQuery method mentioned by Rajeev the other modules will not be aware of the page load requirement.



          The plugin is called domReady! and can be used by adding it as a dependency like so:



          require(["jquery", "domReady!"], function($)
          // Your code here
          );


          This will wait for page load but doesn't necessarily mean it loads after all other KO modules as they may also be waiting for page load. For that reason I think KAndy's method is the most reliable, but this answer may help others.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 21 '17 at 17:43









          Ben CrookBen Crook

          10.1k26 silver badges82 bronze badges




          10.1k26 silver badges82 bronze badges
























              0














              You can try something like this.



              <script type="text/javascript">
              require(["jquery"], function($)
              $(function()

              //do your stuff here

              );
              );
              </script>


              This will make sure, your code will get executed only after dom is fully loaded. If you are familiar with jquery, you will be probably know what $(function() ); does. It makes sure code comes inside that anonymous function will get executed only after DOM is completely loaded.






              share|improve this answer




















              • 1





                Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

                – Mukesh Chapagain
                Feb 12 '17 at 16:38
















              0














              You can try something like this.



              <script type="text/javascript">
              require(["jquery"], function($)
              $(function()

              //do your stuff here

              );
              );
              </script>


              This will make sure, your code will get executed only after dom is fully loaded. If you are familiar with jquery, you will be probably know what $(function() ); does. It makes sure code comes inside that anonymous function will get executed only after DOM is completely loaded.






              share|improve this answer




















              • 1





                Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

                – Mukesh Chapagain
                Feb 12 '17 at 16:38














              0












              0








              0







              You can try something like this.



              <script type="text/javascript">
              require(["jquery"], function($)
              $(function()

              //do your stuff here

              );
              );
              </script>


              This will make sure, your code will get executed only after dom is fully loaded. If you are familiar with jquery, you will be probably know what $(function() ); does. It makes sure code comes inside that anonymous function will get executed only after DOM is completely loaded.






              share|improve this answer













              You can try something like this.



              <script type="text/javascript">
              require(["jquery"], function($)
              $(function()

              //do your stuff here

              );
              );
              </script>


              This will make sure, your code will get executed only after dom is fully loaded. If you are familiar with jquery, you will be probably know what $(function() ); does. It makes sure code comes inside that anonymous function will get executed only after DOM is completely loaded.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 12 '17 at 12:50









              Rajeev K TomyRajeev K Tomy

              14.8k5 gold badges45 silver badges92 bronze badges




              14.8k5 gold badges45 silver badges92 bronze badges










              • 1





                Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

                – Mukesh Chapagain
                Feb 12 '17 at 16:38













              • 1





                Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

                – Mukesh Chapagain
                Feb 12 '17 at 16:38








              1




              1





              Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

              – Mukesh Chapagain
              Feb 12 '17 at 16:38






              Thanks for the answer but it didn't work. The jQuery code runs before KnockoutJS renders DOM elements.

              – Mukesh Chapagain
              Feb 12 '17 at 16:38












              0














              The document ready or DOM loaded events won't be fired on completion of UI form loading.



              Here, either you shall have to write a function in javascript which should be called at some interval and as soon as your target element appears in DOM, process your business logic and clear the interval.



              Another option could be - to execute your JavaScript business logic after completion of AJAX request which can be achieved using following code block.



              $(document).ajaxComplete(function() 
              // enter your code here
              );





              share|improve this answer





























                0














                The document ready or DOM loaded events won't be fired on completion of UI form loading.



                Here, either you shall have to write a function in javascript which should be called at some interval and as soon as your target element appears in DOM, process your business logic and clear the interval.



                Another option could be - to execute your JavaScript business logic after completion of AJAX request which can be achieved using following code block.



                $(document).ajaxComplete(function() 
                // enter your code here
                );





                share|improve this answer



























                  0












                  0








                  0







                  The document ready or DOM loaded events won't be fired on completion of UI form loading.



                  Here, either you shall have to write a function in javascript which should be called at some interval and as soon as your target element appears in DOM, process your business logic and clear the interval.



                  Another option could be - to execute your JavaScript business logic after completion of AJAX request which can be achieved using following code block.



                  $(document).ajaxComplete(function() 
                  // enter your code here
                  );





                  share|improve this answer













                  The document ready or DOM loaded events won't be fired on completion of UI form loading.



                  Here, either you shall have to write a function in javascript which should be called at some interval and as soon as your target element appears in DOM, process your business logic and clear the interval.



                  Another option could be - to execute your JavaScript business logic after completion of AJAX request which can be achieved using following code block.



                  $(document).ajaxComplete(function() 
                  // enter your code here
                  );






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 20 at 7:21









                  AnkitKAnkitK

                  811 silver badge3 bronze badges




                  811 silver badge3 bronze badges






























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f159427%2fmagento-2-run-execute-javascript-after-knockoutjs-has-rendered-all-elements%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                      Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?