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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:12:25+00:00 2026-06-16T16:12:25+00:00

I’m trying to attach validation to a mapped view. I’m using Knockout Mapping and

  • 0

I’m trying to attach validation to a mapped view.
I’m using Knockout Mapping and Validation plugins.
Pseudo-models:

Person {
    int Id;
    string Name;
    Book[] Books;
}

Book {
    int Id;
    string Name;
}

Javascript:

function viewModel() {
    var self = this;
    self.persons = ko.observableArray();

    // persons are retrieved via AJAX...
    ko.mapping.fromJS(persons, {}, self.persons);
}

jQuery(function( $ ) {
    ko.applyBindings(new viewModel());
});

How can I extend persons observableArray to set validation rules and message?
I need to validate both persons and books sub-array properties.
I’ve found only examples that use explicit model setting, without automatic mapping, something like:

Name: ko.observable().extend({ required: true })

Then I’ll need to set ko.validatedObservable, isValid and validation.init, but I really don’t know how to handle/organize this. Can you please provide some help?

  • 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-16T16:12:26+00:00Added an answer on June 16, 2026 at 4:12 pm

    I have found at least two ways to supply validations to model or view model objects that are created via the ko.mapping plugin:

    1. Use the mapping options to attach the validation rules when certain properties are created
    2. HTML5 attributes. This is only supported for some validations (i.e. required, pattern). See the documentation for the Knockout-Validation plugin for details

    The above two techniques can also be combined. See the following fiddle for an example.


    1. Using Mapping Options

    The Knockout Mapping plugin allows the creation of certain properties on mapped objects to be customized. Taking advantage of this functionality, you can override the default behavior of the plugin and add validation for your mapped properties. Below is an example

    HTML

    <input data-bind="value: name" />
    

    Javascript

    var data = { name: "Joe Shmo" };
    
    var validationMapping = {
        // customize the creation of the name property so that it provides validation
        name: {
            create: function(options) {
                return ko.observable(options.data).extend( {required: true} );
            }
        }
    };
    
    var viewModel = ko.validatedObservable(ko.mapping.fromJS(data, validationMapping));
    ko.applyBindings(viewModel);
    

    2. HTML5 Attributes

    The Knockout Validation plugin supports a limited set of HTML5 validation attributes that can be used in your HTML controls. However, using them requires enabling the parseInputAttributes option. Here is a simple example:

    HTML

    <input data-bind="value: name" required />
    

    Javascript

    // this can also be configured through the "validationOptions" binding (https://github.com/ericmbarnard/Knockout-Validation/wiki/Validation-Bindings)
    ko.validation.configure({
        parseInputAttributes: true
    });
    
    var data = { name: "Joe Shmo" };
    
    var viewModel = ko.validatedObservable(ko.mapping.fromJS(data));
    ko.applyBindings(viewModel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.