{"comment":{"created_at":"2011-10-26T21:03:53Z","body":"@dswitzer - my initial thought was that the methods should exist on the view, since they are view-specific formatting needs.\r\n\r\n````MyView = Backbone.View.extend({\r\n  someFormatter: function(someField){\r\n    return someField + \" some other data\";\r\n  }\r\n});\r\n\r\n<div id=\"whatever\" data-bind=\"fn:someFormatter myField\"></div>\r\n````\r\n\r\n\r\nBut, a developer would likely want to create their own helper object that contains a group of formatting functions, so that they can have some consistency between views.\r\n\r\nWould it make sense to default a function call to the view, and then if they provide a \".\", we look up the object / namespace?\r\n\r\n````\r\nmyHelpers = {\r\n  someFormatter: function(){ ... }\r\n}\r\n\r\n\r\n<div id=\"whatever\" data-bind=\"fn:myHelpers.someFormatter someField\"></div>\r\n````\r\n\r\nIt would be a little more code to recognize the \".\" and then parse out a namespace / object / function to call... but I think it would add a lot of flexibility and capabilities. Then a person could attach the formatter functions to the window object, or to the view, or anywhere they want.\r\n\r\nI think defaulting to a method on the view is a good idea, too, in case the dev needs something specific to that view.\r\n\r\nAs for the signature of the method, I'm thinking we'll need to pass in the model, the attribute changing, and the new value, so that we can support external objects with methods. We should also require a return value, as the value to populate into the element.\r\n\r\n````foo.bar = {\r\n  baz: function(model, field, value){\r\n    return formattedValue;\r\n  }\r\n}\r\n````\r\n\r\nHow does all that sound?","updated_at":"2011-10-26T21:03:53Z","url":"https://api.github.com/repos/derickbailey/backbone.modelbinding/issues/comments/2536423","id":2536423,"user":{"avatar_url":"https://secure.gravatar.com/avatar/e592bd1326b1e80188ed4c0bf26b9f75?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"e592bd1326b1e80188ed4c0bf26b9f75","url":"https://api.github.com/users/derickbailey","id":75190,"login":"derickbailey"}},"action":"created","issue":{"number":28,"created_at":"2011-10-11T16:35:20Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"I'd love to see a way to trigger a callback function for updating HTML elements (non-form elements.) \r\n\r\nA couple of use cases:\r\n\r\n* Applying a formatting mask to input\r\n* Creating a mailto: link for an e-mail address\r\n\r\nThe simplest solution to implement would probably be to add another data-bind formatting option, so you could do:\r\n\r\n```\r\n<div id=\"user-email\" data-bind=\"fn:window.formatEmail email\"></div>\r\n```\r\n\r\nThe you'd then write your function like:\r\n\r\n```\r\nfunction formatEmail(element, value){\r\n  var $a = $(\"a\").attr(\"href\", \"mailto:\" + value).text(value).appendTo(element);\r\n}\r\n```\r\n\r\nThis would give you complete control over everything. I'd prefer a way to map a callback function directly within the view itself, so that all my JS logic is in one place, but this would probably be the easiest way to get something into the code.","comments":6,"title":"Format callback for bound HTML elements","updated_at":"2011-10-26T21:03:53Z","url":"https://api.github.com/repos/derickbailey/backbone.modelbinding/issues/28","id":1878157,"assignee":null,"milestone":null,"closed_at":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/f3018d14b9c3d18e7c10ce34215b0f6c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"f3018d14b9c3d18e7c10ce34215b0f6c","url":"https://api.github.com/users/dswitzer","id":900497,"login":"dswitzer"},"html_url":"https://github.com/derickbailey/backbone.modelbinding/issues/28","labels":[],"state":"open"},"legacy":{"issue_id":1878157,"comment_id":2536423}}