Undefined value of $parent in KO templateUndefined index on template fileMagento 2: Can't call parent...

How do I append a character to the end of every line in an excel cell?

What is the difference between rolling more dice versus fewer dice?

Play Zip, Zap, Zop

Is this ordinary workplace experiences for a job in Software Engineering?

Constexpr if with a non-bool condition

Looking for a specific 6502 Assembler

How much mayhem could I cause as a fish?

local storage : Uncaught TypeError: Cannot set property 'innerHTML' of null

Would tunnel walls be stronger if built using cut granite block walls reinforced with carbon based cords?

Square Root Distance from Integers

Cat is tipping over bed-side lamps during the night

Is using an 'empty' metaphor considered bad style?

Why is Agricola named as such?

How to visualize the Riemann-Roch theorem from complex analysis or geometric topology considerations?

Airplane generations - how does it work?

Why would space fleets be aligned?

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

How to politely refuse in-office gym instructor for steroids and protein

How to use Mathemaica to do a complex integrate with poles in real axis?

Why did Luke use his left hand to shoot?

Does Skippy chunky peanut butter contain trans fat?

What is a good reason for every spaceship to carry a weapon on board?

Which communication protocol is used in AdLib sound card?

TikZ graph edges not drawn nicely



Undefined value of $parent in KO template


Undefined index on template fileMagento 2: Can't call parent function in JS / knockout fileMagento 2 custom module override knockout templateMagento 2 Add new field to Magento_User admin formMagento 2 : Translate string in function in knockout templateMagento 2: html template not loadingmagento 2 : knockout value render not working under script templatemagento2 check if customer is logged in or not in knockout templateFormat price value in knockout templateKnockout : Read parent of parent data













0















I've faced with a problem related to calling a function of $parent in the foreach loop.



I'm trying to create a form where there is an opportunity dynamically adding fields (something like this https://stackoverflow.com/questions/39278461/knockout-removing-a-clicked-row#answer-39278949)



<form class="form">
<fieldset class="fieldset" data-bind="foreach: inputs">
<div class="field required">
<label class="label" data-bind="attr: {for: 'number'+($index()+1)}">
<!-- ko i18n: 'Row' --><!-- /ko -->
</label>
<div class="control">
<input class="input-text"
type="text"
name="numbers[]"
data-validate="{required:true}"
data-bind="attr: {title: $t('Row')}"
aria-required="true">
<!-- ko if: $parent.inputs().length > 1 -->
<button class="action default" data-bind="click: $parent.remove, attr: {title: $t('Remove')}">
<!-- ko i18n: 'Remove' --><!-- /ko -->
</button>
<!-- /ko -->
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<button class="action submit primary" data-bind="click: add, attr: {title: $t('Add')}">
<span><!-- ko i18n: 'Add' --><!-- /ko --></span>
</button>
<button type="submit" class="action submit primary" data-bind="attr: {title: $t('Submit')}">
<span><!-- ko i18n: 'Submit' --><!-- /ko --></span>
</button>
</div>
</form>


So after clicking on the Add button, everything is fine. The issue in the Remove button. The component and functions look like code below:



define(['uiComponent', 'ko'], function (Component, ko) {
return Component.extend({
defaults: {
-------------------------------
inputs: ko.observableArray([0])
},
initialize: function () {
this._super();
},
----------
remove: function (data) {
this.inputs.remove(data);
}
});
});



Ko Context debugger shows that there is $parent parent



enter image description here



But after clicking on the remove button I get error in console:



enter image description here



Also after debugging I found that when we are in the remove function, "this" is Number. I don't have ideas why it is Number instead of uiComponent. This is the main reason why it is not working.
enter image description here



Please, help :)










share|improve this question



























    0















    I've faced with a problem related to calling a function of $parent in the foreach loop.



    I'm trying to create a form where there is an opportunity dynamically adding fields (something like this https://stackoverflow.com/questions/39278461/knockout-removing-a-clicked-row#answer-39278949)



    <form class="form">
    <fieldset class="fieldset" data-bind="foreach: inputs">
    <div class="field required">
    <label class="label" data-bind="attr: {for: 'number'+($index()+1)}">
    <!-- ko i18n: 'Row' --><!-- /ko -->
    </label>
    <div class="control">
    <input class="input-text"
    type="text"
    name="numbers[]"
    data-validate="{required:true}"
    data-bind="attr: {title: $t('Row')}"
    aria-required="true">
    <!-- ko if: $parent.inputs().length > 1 -->
    <button class="action default" data-bind="click: $parent.remove, attr: {title: $t('Remove')}">
    <!-- ko i18n: 'Remove' --><!-- /ko -->
    </button>
    <!-- /ko -->
    </div>
    </div>
    </fieldset>
    <div class="actions-toolbar">
    <button class="action submit primary" data-bind="click: add, attr: {title: $t('Add')}">
    <span><!-- ko i18n: 'Add' --><!-- /ko --></span>
    </button>
    <button type="submit" class="action submit primary" data-bind="attr: {title: $t('Submit')}">
    <span><!-- ko i18n: 'Submit' --><!-- /ko --></span>
    </button>
    </div>
    </form>


    So after clicking on the Add button, everything is fine. The issue in the Remove button. The component and functions look like code below:



    define(['uiComponent', 'ko'], function (Component, ko) {
    return Component.extend({
    defaults: {
    -------------------------------
    inputs: ko.observableArray([0])
    },
    initialize: function () {
    this._super();
    },
    ----------
    remove: function (data) {
    this.inputs.remove(data);
    }
    });
    });



    Ko Context debugger shows that there is $parent parent



    enter image description here



    But after clicking on the remove button I get error in console:



    enter image description here



    Also after debugging I found that when we are in the remove function, "this" is Number. I don't have ideas why it is Number instead of uiComponent. This is the main reason why it is not working.
    enter image description here



    Please, help :)










    share|improve this question

























      0












      0








      0








      I've faced with a problem related to calling a function of $parent in the foreach loop.



      I'm trying to create a form where there is an opportunity dynamically adding fields (something like this https://stackoverflow.com/questions/39278461/knockout-removing-a-clicked-row#answer-39278949)



      <form class="form">
      <fieldset class="fieldset" data-bind="foreach: inputs">
      <div class="field required">
      <label class="label" data-bind="attr: {for: 'number'+($index()+1)}">
      <!-- ko i18n: 'Row' --><!-- /ko -->
      </label>
      <div class="control">
      <input class="input-text"
      type="text"
      name="numbers[]"
      data-validate="{required:true}"
      data-bind="attr: {title: $t('Row')}"
      aria-required="true">
      <!-- ko if: $parent.inputs().length > 1 -->
      <button class="action default" data-bind="click: $parent.remove, attr: {title: $t('Remove')}">
      <!-- ko i18n: 'Remove' --><!-- /ko -->
      </button>
      <!-- /ko -->
      </div>
      </div>
      </fieldset>
      <div class="actions-toolbar">
      <button class="action submit primary" data-bind="click: add, attr: {title: $t('Add')}">
      <span><!-- ko i18n: 'Add' --><!-- /ko --></span>
      </button>
      <button type="submit" class="action submit primary" data-bind="attr: {title: $t('Submit')}">
      <span><!-- ko i18n: 'Submit' --><!-- /ko --></span>
      </button>
      </div>
      </form>


      So after clicking on the Add button, everything is fine. The issue in the Remove button. The component and functions look like code below:



      define(['uiComponent', 'ko'], function (Component, ko) {
      return Component.extend({
      defaults: {
      -------------------------------
      inputs: ko.observableArray([0])
      },
      initialize: function () {
      this._super();
      },
      ----------
      remove: function (data) {
      this.inputs.remove(data);
      }
      });
      });



      Ko Context debugger shows that there is $parent parent



      enter image description here



      But after clicking on the remove button I get error in console:



      enter image description here



      Also after debugging I found that when we are in the remove function, "this" is Number. I don't have ideas why it is Number instead of uiComponent. This is the main reason why it is not working.
      enter image description here



      Please, help :)










      share|improve this question














      I've faced with a problem related to calling a function of $parent in the foreach loop.



      I'm trying to create a form where there is an opportunity dynamically adding fields (something like this https://stackoverflow.com/questions/39278461/knockout-removing-a-clicked-row#answer-39278949)



      <form class="form">
      <fieldset class="fieldset" data-bind="foreach: inputs">
      <div class="field required">
      <label class="label" data-bind="attr: {for: 'number'+($index()+1)}">
      <!-- ko i18n: 'Row' --><!-- /ko -->
      </label>
      <div class="control">
      <input class="input-text"
      type="text"
      name="numbers[]"
      data-validate="{required:true}"
      data-bind="attr: {title: $t('Row')}"
      aria-required="true">
      <!-- ko if: $parent.inputs().length > 1 -->
      <button class="action default" data-bind="click: $parent.remove, attr: {title: $t('Remove')}">
      <!-- ko i18n: 'Remove' --><!-- /ko -->
      </button>
      <!-- /ko -->
      </div>
      </div>
      </fieldset>
      <div class="actions-toolbar">
      <button class="action submit primary" data-bind="click: add, attr: {title: $t('Add')}">
      <span><!-- ko i18n: 'Add' --><!-- /ko --></span>
      </button>
      <button type="submit" class="action submit primary" data-bind="attr: {title: $t('Submit')}">
      <span><!-- ko i18n: 'Submit' --><!-- /ko --></span>
      </button>
      </div>
      </form>


      So after clicking on the Add button, everything is fine. The issue in the Remove button. The component and functions look like code below:



      define(['uiComponent', 'ko'], function (Component, ko) {
      return Component.extend({
      defaults: {
      -------------------------------
      inputs: ko.observableArray([0])
      },
      initialize: function () {
      this._super();
      },
      ----------
      remove: function (data) {
      this.inputs.remove(data);
      }
      });
      });



      Ko Context debugger shows that there is $parent parent



      enter image description here



      But after clicking on the remove button I get error in console:



      enter image description here



      Also after debugging I found that when we are in the remove function, "this" is Number. I don't have ideas why it is Number instead of uiComponent. This is the main reason why it is not working.
      enter image description here



      Please, help :)







      magento2 javascript template knockoutjs knockout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 10 mins ago









      Dmitriy ChizhovDmitriy Chizhov

      265




      265






















          0






          active

          oldest

          votes











          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%2f263626%2fundefined-value-of-parent-in-ko-template%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f263626%2fundefined-value-of-parent-in-ko-template%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

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...