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 6675659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:53:06+00:00 2026-05-26T03:53:06+00:00

In the following code the idea is that if you fill in ‘test’ that

  • 0

In the following code the idea is that if you fill in ‘test’ that this is considered invalid and shouldn’t write the value to the observable. The problem I have is that my custom binding is somehow resetting the observable’s value.

A working version of the code below: http://jsfiddle.net/6hcpM/1/

var underlying = ko.observable('foo');
var errors = ko.observableArray()
var isValid = ko.dependentObservable(function(){
    return errors().length === 0
});

var vm = {
    name : ko.dependentObservable({
        read : underlying,
        write : function(value){
            errors([]);

            if(value==='test'){
             errors([ 'Cant be test matey' ]);   
            };

            if(isValid()){
              underlying(value);
            };
        }
    })
};

vm.name.isValid = isValid;

ko.bindingHandlers.validateCss = {
    update: function(element, valueAccessor) {
       observable = valueAccessor();
       observable.isValid(); //this somehow causes the problem
    }
};

ko.applyBindings(vm);
  • 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-05-26T03:53:07+00:00Added an answer on May 26, 2026 at 3:53 am

    Your validateCss binding creates a dependency to vm.name.isValid. When you write “test” to the field, errors is updated, which causes isValid to update, which triggers all of the bindings in the input’s data-bind attribute to be re-evaluated. So, the value binding gets evaluated again and replaces the current value with the value from name (which is stored in underlying).

    So, basically the value binding is running again based on isValid changing.

    There are several ways that you could handle it. You could let underlying get updated every time and, if necessary, store a clean value elsewhere that only gets updated when it is valid.

    You could also put your custom binding on a different element. For example, you could wrap your input in a span or div and put the binding on it. I assume that you want the validateCss binding to assign a CSS class when the value is invalid.

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

Sidebar

Related Questions

I have absolutely no idea why this is happening but the following code seems
I can't run following code with IDEA @Test class CompanyURLTest extends Assert { @Test
The following code is an attempt to write a variadic function that acts like
i have following code for implement IntegerSet Class,idea is that when i insert element
Any idea why the following code doesn't print the amount of characters in the
Any idea why the following code is not working mysql credentials are correct, have
Do you have any idea, why the following code: public class A { public
One of the following pieces of code generates a memory leak, any idea which
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
i've got this snazzy python code: import subprocess value = subprocess.Popen([php,./php/php_runner.php],stdout=subprocess.PIPE); the problem is,

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.