Chitika

February 4, 2013

Knockout validation: Сomparison of the two fields

I would like to share how I've solved this problem.

The typical example is a simple registration form with the view model:

    var viewModel = ko.validatedObservable({
        userName: ko.observable().extend({ required: true }),
        password: ko.observable().extend({ required: true }),
        passwordConfirm: ko.observable().extend({ required: true })
    });

Then you can easily check is your viewModel valid using:

    viewModel.isValid();

And it works very good. But you don't have validation are your password and password confirmation fields equal.

To do it you have to add these lines:

    viewModel().password.extend({ equal: viewModel().passwordConfirm });
    viewModel().passwordConfirm.extend({ equal: viewModel().password });

After that you will have client notification as well as ability to check is your view model valid in code (as mentioned above).

That's all.
Good luck.

24 comments:

  1. I just want to say I’m new to blogs and seriously loved this web site. Probably I’m likely to bookmark your blog post . You really have great stories. Regards for revealing your web site.

    Linux Training in Chennai Velachery

    ReplyDelete
  2. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  3. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    seo Company in India

    ReplyDelete
  4. Hi,
    I have read your previous posts recently , and let me tell you, your website gives the
    best and the most interesting information. This is just the kind of information that i had
    been looking for.
    Thank you.
    oracle R12 training

    ReplyDelete
  5. I have just read your site, If you are looking for best Oracle financials also giving all software Course Online Training.The oracle Online Training is one of the leading Online Training institute in Hyderabad.
    Oracle fusion financials training

    ReplyDelete


  6. Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

    Installment loans
    Payday loans
    Title loans

    ReplyDelete

  7. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Android App Development Company

    ReplyDelete
  8. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    iOS App Development Company
    iOS App Development Company

    ReplyDelete
  9. Good post and I like it very much. By the way, anybody try this app development company for iOS and Android? I find it is so professional to help me boost app ranking and increase app downloads.

    ReplyDelete
  10. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    PSD to Wordpress
    wordpress website development

    ReplyDelete
  11. You really did a great job. I found your blog very interesting and very informative. I think your blog is great information source & I like your way of writing and explaining the topics. Keep it up.
    Oracle Fusion HCM Technical Training in Ameerpet

    ReplyDelete
  12. Harvard Business Review named data scientist the "sexiest job of the 21st century".This Data Science course will cover the whole data life cycle ranging from Data Acquisition and Data Storage using R-Hadoop concepts, Applying modelling through R programming using Machine learning algorithms and illustrate impeccable Data Visualization by leveraging on 'R' capabilities.With companies across industries striving to bring their research and analysis (R&A) departments up to speed, the demand for qualified data scientists is rising.

    data science training in bangalore

    ReplyDelete
  13. myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    aws training in bangalore

    ReplyDelete
  14. Big Data and Hadoop is an ecosystem of open source components that fundamentally changes the way enterprises store, process, and analyze data.
    hadoop training in bangalore

    ReplyDelete
  15. IOT Training in Bangalore - Live Online & Classroom
    Iot Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Iot Training in Bangalore

    ReplyDelete
  16. Gaining Python certifications will validate your skills and advance your career.
    python certification

    ReplyDelete
  17. Devops is not a Tool.Devops Is a Practice, Methodology, Culture or process used in an Organization or Company for fast collaboration, integration and communication between Development and Operational Teams. In order to increase, automate the speed of productivity and delivery with reliability.

    python training in bangalore
    aws training in bangalore
    artificial intelligence training in bangalore
    data science training in bangalore
    machine learning training in bangalore
    hadoop training in bangalore
    devops training in bangalore

    ReplyDelete
  18. Thanks for your great and helpful presentation I like your good service.I always appreciate your post.That is very interesting I love reading and I am always searching for informative information like this.Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chennai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery

    ReplyDelete