update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var settings; var newValueAccessor; var elementHasFocus;
settings = ko.unwrap(valueAccessor()) || {}; afterRender = settings.afterRender || null;
// create a new value accessor to include the afterRender callback newValueAccessor = function () { return settings.data; };
// call the underlying textInput update to have KO do its normal processing but using // the new value accessor with the added event handlers ko.bindingHandlers.text.update(element, newValueAccessor, allBindingsAccessor, viewModel, bindingContext); // Flag whether the curent element has focus elementHasFocus = $(element).is(":focus");
// text.update wipes out placeholder text if it is present, even when the new value is an empty string. So, we want to replace it here, but only // if the current element does not have focus. If the element DOES have focus, it will cause the user to be required to delete the placeholder text before // tabbing away in order to prevent the placeholder text from updating the underlying observable. There was also some inconsistent behavior which at times prevented // the placeholder text from being deleted at all. if ((element.innerText.length == 0) && (elementHasFocus != true)) { ko.utils.setTextContent(element, element.placeholder); }
if (afterRender !== null) { afterRender(element, settings.data); } }
ko.unwrap(settings.data);
Thanks but I'm not sure how that would ensure that the text area has been updated with the observable value before my afterRender callback is called?
--
You received this message because you are subscribed to a topic in the Google Groups "KnockoutJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/knockoutjs/KWTAZBNdY1E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "KnockoutJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/knockoutjs/KWTAZBNdY1E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ko.bindingHandlers.textInputWithAfterRenderCallback ={ init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { var settings; var newValueAccessor;
settings = ko.unwrap(valueAccessor()) || {};
newValueAccessor = function () { return settings.data; };
return ko.bindingHandlers.textInput.init(element, newValueAccessor, allBindingsAccessor, viewModel, bindingContext); },