1

I would like to do 2 thinks with knockout js and UI component

  1. Fill in input in a grid based on entity_id - Works great
  2. Trigger callback when one of input has changed

The second part works partly. When I am using collectionDates as string then all of the input will get same value and when one of the input are changed then valueChanged method is called.

When collectionDates is set as an array (so that every input can have it's own value) then the callback wont trigger when any of inputs value change. Reading knockout js documentation for observable arrays I believe this should be possible. Why magento 2 UI component does not track changes of array elements?

define([
 'jquery',
 'Magento_Ui/js/grid/columns/column'
], function (,ドル Column) {
 'use strict';
 return Column.extend({
 defaults: {
 collectionDates: {
 19: 100,
 21: 200
 },
 listens:{
 collectionDates: 'valueChanged'
 }
 },
 initObservable: function () {
 return this._super()
 .track(['collectionDates']);
 },
 valueChanged: function (val, val2, val3) {
 debugger
 }
 });
});

Template used for input

<input
 type="text"
 data-bind="value: collectionDates[$row().entity_id]"
/>
asked May 25, 2020 at 15:48
1
  • So far I have found that I could use event: {change: valueChanged} in data-bind. Still this does not feel right. I am staring to wonder if this is some kind of a bug? Commented May 25, 2020 at 19:04

1 Answer 1

0

I researched this topic for 2 day and found that it isn't that simple. This could be done but needs custom bindings. Something similar to staticChecked binding found in multi select column component (ui/grid/cells/multiselect).

Binding itself is located here

C:\Users\Pisikoll\Documents\drive-innMagento\vendor\magento\module-ui\view\base\web\js\lib\knockout\bindings\staticChecked.js

For now without writing complicated code events are the way to go.

answered May 26, 2020 at 22:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.