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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:05:19+00:00 2026-06-11T20:05:19+00:00

I am working on KnockOut validation and so far so good. I do have

  • 0

I am working on KnockOut validation and so far so good. I do have a question though. I have some code like the following:

 shippingMethodModel.Description.extend({ required: true });

And that shows a validation message below BUT does it set a flag or something which I can read to disable my save button?

  • 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-11T20:05:20+00:00Added an answer on June 11, 2026 at 8:05 pm

    I had this same need recently, so I’ll try to translate what I did based on the line of code you provided above…

    Try adding a ko.computed observable similar to the following:

    shippingMethodModel.formIsNotValid = ko.computed(function () {
        // original line
        // var errors = ko.utils.unwrapObservable(ko.validation.group(self));
    
        // ** oops, not "self" in this case
    
        // UPDATED line
        var errors = ko.utils.unwrapObservable(ko.validation.group(shippingMethodModel));
        return (errors.length > 0);
    });
    

    UPDATE
    I made a correction in the code above after noticing my error.

    For those declaring such a model/class as a function all at once, this code may look similar to the following:

    var ShippingMethodModel = function () {
        var self = this;
        self.shippingMethodId = ko.observable().extend({ required: true });
        self.description = ko.observable().extend({ required: true });
    
        self.formIsNotValid = ko.computed(function () {
            var errors = ko.utils.unwrapObservable(ko.validation.group(self));
            return (errors.length > 0);
        });
    };
    

    /UPDATE

    UPDATE2
    Based on input from @ericb in the comments below, I made a change to the way I’m implementing my own solution, which I’ll demonstrate by adapting the example code in my update above:

    var ShippingMethodModel = function () {
        var self = this;
        self.shippingMethodId = ko.observable().extend({ required: true });
        self.description = ko.observable().extend({ required: true });
    
        self.formIsNotValid = ko.observable(false);
    
        self.validateObservableFormField = function (nameOfObservableToValidate, 
                                                     data, event) {
            for (var prop in data) {
                if (prop === nameOfObservableToValidate) {
                    var theObservable = data[prop];
                    theObservable.valueHasMutated();
                    ko.validation.validateObservable(theObservable);
                    if (theObservable.error) {
                        self.formIsNotValid(true);
                    }
                    else {
                        if (self.formIsNotValid()) {
                            var errors = 
                                ko.utils.unwrapObservable(ko.validation.group(self));
                            self.formIsNotValid(errors.length > 0);
                        }
                    }
                    return;
                }
            }
        };        
    };
    

    Notice that I’ve now defined formIsNotValid as an observable, but I’m using the validateObservableFormField function to help me with pre-submit form validity determination. This change ensures that the ko.validation.group function is called only as needed, and that call should only be needed when the observable being validated is valid, but formIsNotValid is true (to handle the case where that current observable was the one that had set formIsNotValid to true).

    Here’s an example of how I’m doing this:

    <input data-bind="value: description, 
                      event: { blur: function(data, event) {
                                         validateObservableFormField('facilityName', 
                                                                      data, 
                                                                      event) 
                                     }
                             }" />
    

    goofy formatting to eliminate horizontal scroll

    NOTE: I was already using this technique, but I’ve adapted it to improve the performance of checking whether or not the form is valid. @Californicated, I realized after my last comment that calling this function from the blur event of validated form fields is why I was seeing my save/submit button toggle between enabled and disabled states.

    Thanks again to @ericb for the performance tip.

    Further tips, from anyone, are always welcome!

    /UPDATE2

    Once you’ve got that in place, disabling the button is a matter of binding to that formIsNotValid computed observable in whatever way makes sense for how you intend to disable the button, e.g. css: { 'ui-state-disabled': formIsNotValid } and/or disable: formIsNotValid and/or some other method(s).

    Hope this helps, and let me know if you run into trouble.

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

Sidebar

Related Questions

I have a piece of code working in knockout.js like this: <div> ... some
I am using Knockout Validation and have everything working as I wanted. I am
This is a general question, but I'd love some feedback. I'm new to working
I was following a video about knockout and I have no idea why my
working on an old translation sample code for windows phone 7. Recently, I have
i have the next scenario: Im working with knockout (ver 2.1.0) and ASP MVC.NET,
I have a listview like the following: <ul data-inset=true data-filter=true data-bind=foreach: growers data-role=listview id=ulGrowerList>
I'm working with Kendo UI and Knockout JS libraries and have a strange problem.
Am working with knockout template binding, i just want to know is there any
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports

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.