1

I created a UI Component form, but I am unable to find the element in the source.

I would like to click a button and then inspect a field in the form and dependent on what value is selected submit the form to a specific url.

In my uiComponent I have,

 <argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">            
        <item name="component" xsi:type="string">Vendor_Module/js/ui/form/new_form</item>
    </item>

Then I have the following code in Vendor_Module/js/ui/form/new_form:

define(
[
    'jquery',
    'Magento_Ui/js/form/form',
    'mage/url'
],
function ($, form, url) {
    'use strict';

    return form.extend({
        initialize: function () {
            this._super();

            $('#new_button').click(this.new_button);

            return this;
        },
        new_button: function (redirect, data) {
            this.validate();

            if (!this.additionalInvalid && !this.source.get('params.invalid')) {

                // CUSTOM CODE HERE BEFORE SUBMIT

                this.setAdditionalData(data)
                    .submit(redirect);
            } else {
                this.focusInvalid();
            }
        }

I am currently getting,

Uncaught TypeError: this.validate is not a function

2
  • Can you please paste your code here? Thanks
    – Shankar
    May 18 '19 at 5:47
  • @Shankar I have added the code as requested. May 19 '19 at 18:57
0

Use the following code to submit the form programmatically

define(
    [
        'jquery',
        'Magento_Ui/js/form/form',
        'mage/url'
    ],
    function ($, form, url) {
        'use strict';

        return form.extend({
            initialize: function () {
                this._super();
                var self = this;
                 $('#new_button').click(function () {
                    self.submit(self.source.submit_url);
                });
                return this;
            },
        })
    }
);

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.