0

Can I call the custom binding called form from another custom binding called addAnother explicitly? Also can I modify the parameters going into the parent custom binding?

    ko.bindingHandlers.addAnother = {
        init: function (element, valueAccessor) {
            $(element).click(function () {
                //$(element).parents('form')....
            });
        }
    };

<form class="box clearfix" action="@Request.RawUrl" data-bind="form:{ id: @Model.Division.Id }">
    @Html.Partial("EditorTemplates/Division", Model.Division)
    <div class="control-group">
        <div class="controls">
            @Html.Partial("EditorTemplates/Button")
            <button class="btn btn-inverse" data-bind="addAnother: { }"><i class="icon-save icon-white"></i> Save +</button>

        </div>
    </div>
</form>
JotaBe
  • 38,030
  • 8
  • 98
  • 117
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • Yes, but if the binding is on another element, as in your case, it will be very brittle. What are you trying to do? – Kyeotic Jul 18 '13 at 22:23
  • Trying to have a multiple buttons modify a form submit binding dynamically. – Mike Flynn Jul 18 '13 at 23:49
  • Why not have the buttons call viewmodel functions to modify a viewmodel property, which is accessed by the submit function? It would be a lot simpler. – Kyeotic Jul 19 '13 at 00:17
  • I could, I just like how clean the submit is by sending the form element in its parameter which I need. – Mike Flynn Jul 19 '13 at 16:46
  • Well, you can access an elements binding with `ko.contextFor(element)`, but to get it from the child you will need to do traversals, which are brittle by nature. This will return the binding context of the element, which you can then modify or call. – Kyeotic Jul 19 '13 at 17:32

0 Answers0