Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:07:08+00:00 2026-06-13T05:07:08+00:00

I have a Knockout View with about 50 inputs of various kinds. I already

  • 0

I have a Knockout View with about 50 inputs of various kinds. I already track when a change was made to the model by the following code

self.Changed = ko.computed(function() {
    return ko.toJS(self.Outing);
});

And then subscribing to the Changed function to save the model back to the server. What I would like to accomplish is when a user changes an individual input it triggers a css binding on that input to highlight it so the user knows what he/she changed. How can I do this with out individually subscribing to each observable property?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:07:09+00:00Added an answer on June 13, 2026 at 5:07 am

    There are a few ways that you could handle something like this. A convenient way to do this might be a custom binding that grabs the original value and sets up a css binding against a computed that looks at the original vs. current value.

    Maybe something like:

    ko.bindingHandlers.changedCss = {
        init: function(element, valueAccessor, allBindings) {
            var original, isDirty, data, cssClass, binding;
    
            data = allBindings().value;
            original = ko.utils.unwrapObservable(data);
            isDirty = ko.computed({
                read: function() {
                    return ko.utils.unwrapObservable(data) !== original;
                },            
                disposeWhenNodeIsRemoved: element
            });
    
            cssClass = ko.utils.unwrapObservable(valueAccessor());
            binding = { css: {} };
            binding.css[cssClass] = isDirty;
    
            ko.applyBindingsToNode(element, binding);       
        }                          
    };
    

    You would use it like: <input data-bind="value: first, changedCss: 'changed'" />

    So, the idea is that we look for what the value binding is bound against and set up a computed observable on-the-fly to give us a dirty flag for this property. Then, programmatically add a css binding using the class name that was passed to the binding.

    http://jsfiddle.net/rniemeyer/PCmma/

    Alternatively, you could create an extension that would let you add this dirty tracking from the view model side. This would give you some additional flexibility, like the ability to reset the tracking (consider the current value to be clean). For starters, you could do something like:

    ko.subscribable.fn.trackDirtyFlag = function() {
        var original = this();
    
        this.isDirty = ko.computed(function() {
            return this() !== original;
        }, this);
    
        return this;    
    };
    

    Then, use it like: this.first = ko.observable("John").trackDirtyFlag();

    http://jsfiddle.net/rniemeyer/JtvWd/

    You could then do things like add a reset method that sets original equal to the current value.

    If your goal is just to be able to color the dirty fields, then the custom binding might be a good choice, as you don’t need to change your view model at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have the following code which uses knockout.js, var allJobberDetailsArray = []; getAllJobberDetailsArray();
I have a Knockout view model defined like this: function viewModel () { var
I have a Knockout.js view model that looks like this: UserName:null, FirstName:null, LastName:null, Countries:{
I have the following view model which contains an array of elements function ReservationsViewModel()
If I have a view model that looks like this when using the knockout
I have a big problem with using Knockout JS. In my view model I
I have Knockout.js view model that has nested observable arrays. function ParentVM(data) { var
I have a view model something like below, when onAfterRender is fired by Knockout
I have the following knockout.js code I’ve got the following: var itemLine = function()
I have a knockout model that is feeding my page and on a save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.