1

I am using the "with" binding in knockout.js, and it works fine below in say Chrome and IE9, but when I move to IE8 the form doesnt submit anymore. I remove the "with" it does just fine. In Visual Studio the "with" keyword is blue telling me it's a reserved word. Is there anyway around this for IE8?

<form class="box clearfix" action="@Request.RawUrl" data-bind="with: members.events, form: { id: @Model.Event.Id }">


ko.bindingHandlers.form = {
    init: function (element, valueAccessor) {

        var value = ko.utils.unwrapObservable(valueAccessor());

        $(element).find('button[type=submit]:last').click(function () {

            if (typeof (value.submit) == 'function') {
                value.submit();
            } else {
                app.call({
                    type: 'POST',
                    data: $(element).serializeObject(),
                    url: $(element).attr('action'),
                    success: function (result) {

                        if (value.replace) {
                            app.updateContainerWithHtml(result);
                        } else {
                            if (value && value.id == 0 && typeof(result) == 'string') {
                                window.location.hash = result;
                            } else {
                                if (typeof (value.callback) == 'function') {
                                    value.callback(result);
                                }
                            }

                            if (value.hideSuccess == undefined && !value.hideSuccess) {
                                if (result.Url) {
                                    app.showSuccess(result.Message, function() {
                                        window.location.hash = result.Url;
                                    });
                                } else {
                                    app.showSuccess();
                                }
                            }
                        }
                    }
                });
            }

            return false;
        });

    }
};
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • Maybe can you get something in jsFiddle? Top level keys in the binding are quoted, so the `with/if` is not an issue at that level. What does the `form` binding do? – RP Niemeyer May 11 '13 at 21:02
  • I posted the code above for the form binding. It does basically the same thing as the submit binding, just with extra info passed to it. – Mike Flynn May 12 '13 at 16:51
  • The button click never gets hit. I noticed if I took all my form elements out, and click the button it clicks a different on the page and I noticed jquery was attaching the same dynamic jquery id to both buttons. If I leave the form elements in the jquery ids are different so not sure... – Mike Flynn May 12 '13 at 17:45
  • Does IE8 report any errors with the page? – Michael Best May 13 '13 at 08:00
  • No I believe it has to do with some kind of conflict with either knockout.js or jquery – Mike Flynn May 14 '13 at 18:45
  • This is not a helpful comment but you had help from one of the best in the business @RP Niemeyer :) His knockmeout.net page has taught me so much! – segFault Oct 11 '13 at 05:48

1 Answers1

2

I had the same issue found here

and I just had to refer to my objects with long data-binds like members.events.title instead of title.

My section of code was small as it was just for an attachment section so it wasnt too annoying. You can try escaping the with, like data-bind="'with': , like you do with the ko comments for if's to make them work with IE but I am doubtful that would work.

Community
  • 1
  • 1
segFault
  • 1,228
  • 2
  • 18
  • 41
  • I might have to revert to that, but I just wouldnt think the knockout guys would of use a keyword in IE as a custom binding. – Mike Flynn May 11 '13 at 20:16
  • I'm using with and it works fine in IE8. I think you're chasing the wrong error. – Scott Oct 10 '13 at 20:15
  • I can get with's to work in IE8 but its when it was wrapped around my jquery fileUpload that it crapped out. You can try the type safe jquery calls by using jquery.call instead of $.call – segFault Oct 11 '13 at 05:46