0
votes

I have a table with TRbind in foreach loop:

<tbody data-bind="foreach: data">
    <tr>
        <td><input type="text" class="form-control" data-bind="value: DeviceSerialNumber" required /></td>
        <td><input type="datetime" class="form-control datepicker" placeholder="Od" data-bind="value: StartDate" required /></td>
        <td><button class="btn btn-default" data-bind='click: $root.removeRow'>Delete</button></td>
    </tr>
</tbody>

the button is bind to this function:

    self.removeRow = function (eq) {
        self.data.removeAll([eq]);
    };

I add data in this way:

var a = new Eq();
console.log(self);
a.StartDate(self.StartDateTemp());
a.DeviceId(self.DeviceTemp());
console.log(a);
console.log(self.data().length);
self.data.push(a);
console.log(self.data().length);

and data is:

var ViewModel = function () {
    var self = this;
    self.DeviceTemp = ko.observable();
    self.StartDateTemp = ko.observable();
    self.data = ko.observableArray([]);
}

The problem is occurring only in IE10. If I add anything to the data array the view is Updated. As in the view I add the is button bind to remove at the end of the tr. For unknown reason knockout or browser clicks that button and removes freshly added row.

Can You help me?

JSFIDDLE

1
Could you create a jsfiddle to show your problem? - GôTô
Error exists only in local intranet?? - GôTô
Yes. Only in intranet and only in IE10. In IE11 is working... - szpic
Are you sure that you are not in compatibility mode in IE? - nemesv
Yes I'm sure Im in IE10Mode - szpic

1 Answers

2
votes

Try adding return false after self.data.push(a); self.Test(""); to prevent event from bubbling:

self.searchKeyboardCmd = function (data, event) {
        if (event.keyCode == 13) {
            if ((self.StartDateTemp() === undefined)
                || (self.number() != 1 && self.Test() != undefined)
                && (self.number() != 1 && self.Test() != "")) {

                alert("Bledna konfiguracja. Urzadzenia posiadajace numer seryjny nie moga byc dodane wiecej niz 1 raz")
                return true;
            }
            if (self.number() < 1 || isNaN(self.number())) {
                alert("Bledna ilosc");
                return true;
            }
            var a = new Eq();
            a.StorageId(self.StorageTemp());
            a.StartDate(self.StartDateTemp());
            a.DeviceSerialNumber(self.Test());
            a.DeviceId(self.DeviceTemp());
            a.Issue(self.Issue())
            a.IssueDesc(self.IssueDesc());
            a.Quantity(self.number());
            a.Project(self.Project());
            a.MeUser(self.MeUser());

            self.data.push(a);
            self.Test("");
            return false;
        }
        return true;
    };