0

Using magento 2.2, admin. I need to add textbox into dialog when confirm Cancel status in sale order.

enter image description here

  • You need to change the UI component js and template and your input field. – Milind Singh Dec 3 '18 at 6:39
  • Can you give me more detail? @MilindSingh – Bong Channarith Dec 3 '18 at 8:35
1

create module for override js file
\app\code\Magento\custombackend\etc\module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Magento_custombackend" setup_version="0.0.1">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

\app\code\Magento\custombackend\view\adminhtml\requirejs-config.js

var config = {
    map: {
        '*': {
            'Magento_Sales/order/view/post-wrapper': 'Magento_custombackend/js/order/view/post-wrapper'
        }
    }
};

\app\code\Magento\custombackend\view\adminhtml\web\js\order\view\post-wrapper.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

define([
    'jquery',
    'Magento_Ui/js/modal/confirm',
    'mage/translate'
], function ($, confirm) {
    'use strict';

    /**
     * @param {String} url
     * @returns {Object}
     */
    function getForm(url) {
        return $('<form>', {
            'action': url,
            'method': 'POST'
        }).append($('<input>', {
            'name': 'form_key',
            'value': window.FORM_KEY,
            'type': 'hidden'
        }));
    }

    $('#order-view-cancel-button').click(function () {
        var msg = $.mage.__('Are you sure you want to cancel this order? <input type="text">'),
            url = $('#order-view-cancel-button').data('url');
        confirm({
            'content': msg,
            'actions': {

                /**
                 * 'Confirm' action handler.
                 */
                confirm: function () {
                    getForm(url).appendTo('body').submit();
                }
            }
        });

        return false;
    });

    $('#order-view-hold-button').click(function () {
        var url = $('#order-view-hold-button').data('url');

        getForm(url).appendTo('body').submit();
    });

    $('#order-view-unhold-button').click(function () {
        var url = $('#order-view-unhold-button').data('url');

        getForm(url).appendTo('body').submit();
    });
});

\app\code\Magento\custombackend\registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,    
'Magento_custombackend',    __DIR__);
?>

In magento 2.2.5 this dialog text come from this path \vendor\magento\module-sales\view\adminhtml\web\order\view\post-wrapper.js

line : 29

var msg = $.mage.__('Are you sure you want to cancel this order? <input type="text">')

add textbox like this

enter image description here

  • How to override this file, coz Magento not allow to change file in vendor.? – Bong Channarith Dec 3 '18 at 8:57
  • check updated answer.. deal with create new module for override js file – snkt Dec 4 '18 at 13:51
  • do you have any idea how to get this post value – Vinay Sikarwar Nov 5 '19 at 17:39

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.