0

I need to change product enable option to keep in disabled by default. I used data-index in css to hide the input which works fine but I need to change input tags value. My phtml to switch check box to false is below

<?php 
    $role_id = 1 ; //get user's role id from system configuration
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $adminSession = $objectManager->get('Magento\Backend\Model\Auth\Session');
     $current_adminuser =    $adminSession->getUser()->getRole()->getRoleId();
    if($role_id == $current_adminuser): ?>


  <script>

     var inputs = document.getElementsByTagName('input');

for(var I = 0; i<inputs.length; i++){

  if(typeof inputs[i].getAttribute === 'function' && inputs[i].getAttribute('class') === 'admin__actions-switch-checkbox'){

    inputs[i].checked = false;

    break;

  }
}

  </script>
      <style>
    [data-index=status] {
            display: none;
        }
        </style>
    <?php endif; ?>
1

Your js code is not working because when it is run the element you are searching for is not yet rendered by knockout js.

You can call you code in following snippet to see if it works ;

<script>
require(['uiRegistry'], function (r) {
    r.get("product_form.product_form.product-details.quantity_and_stock_status_qty.qty", function (el) {
      // call your js here
    })
})
</script>
  • This is not working again..no bugs in console..I need to change enable button to keep disabled by default but not working. – Ramesh KR Feb 28 '18 at 6:37

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.