1

The new style of M2 Ui forms using knockout Js has changed many things we do with M1 . My Jquery Tokenizer does not dispaly tokens in edit form, tokens are added successful when we create new token. Below is the code files if someone could figure out.My console displays the error : ReferenceError: tag_names is not defined

Tags Js

define([
'ko',
'jquery',
'Magento_Ui/js/form/element/abstract',
'jquerytokenize'
], function (ko, $, Abstract) {
'use strict';


function updateValue(viewModel, value) {

    viewModel.value(value);
}

ko.bindingHandlers.myTags = {


    init: function (element, valueAccessor, allBindings, viewModel) {
        // document.write(JSON.stringify(element.value));

        if (valueAccessor()) {
            $('#' + element.id).tokenize({


                onAddToken: function (value, text, tokenize) {
                    updateValue(viewModel, tokenize.select.val());
                },


                onRemoveToken: function (value, tokenize) {
                    updateValue(viewModel, tokenize.select.val());
                }
            });
        }
    }
};
return Abstract.extend({
    defaults: {
        template: 'Namespace_Module::/form/element/tags.html'
     }
    });
});

Tags Html

<select multiple class="admin__control-multiselect" data-bind="
attr: {
    name: inputName,
    id: uid,        
    disabled: disabled,
    'aria-describedby': noticeId,
    placeholder: placeholder
},

hasFocus: focused,   
selectedOptions: value,
optionsValue: 'label',
optionsText: 'label',
myTags: true"
 />

Ui Form Field

<field name="tag_names">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">   
                <item name="component" xsi:type="string">Namespace_Module/js/tags</item>
                <item name="componentType" xsi:type="string">field</item>
                <item name="multiple" xsi:type="boolean">true</item>

                <!-- <item name="template" xsi:type="string">ui/form/field</item> -->

                <item name="elementTmpl" xsi:type="string">Namespace_Module/form/element/tags</item>
                <item name="label" xsi:type="string">Article Tags</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">article</item>                   
            </item>
        </argument>

Note: The format of the token's field data is same as it was during the save .

  • Replace template with template: 'Namespace_Module/form/element/tags' – Rakesh Jesadiya Oct 5 '17 at 12:36
  • @Rakesh My console shows the error ReferenceError: tag_names is not defined – Verdu Oct 6 '17 at 6:15

Your Answer

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

Browse other questions tagged or ask your own question.