Knockout-Contrib / Knockout-Contrib/Knockout-Validation

validation is not working when assigning new value to a model

Open
#592 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

When i run the code the validation will work perfectly as soon as i click submit and assign the new value to the self.customer, the validation is not working any more.
The Code is below








Customer name:

Customer Age:


Click To Validate

```

// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
var self = this;
self.customer = ko.observable(new NewCustomer());
self.errors = ko.validation.group(self.customer);

self.submit = function () {
if (self.errors().length > 0) {
self.errors.showAllMessages();
}
else {
console.log(self.customer().age());
self.customer(new NewCustomer());
}
};
}

function NewCustomer() {
var self = this;
self.name = ko.observable().extend({ required: true });;
self.age = ko.observable().extend({ required: true });;
}

// Activates knockout.js
ko.applyBindings(new AppViewModel(), document.getElementById('ko-content'));

```

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied HTML and JavaScript example with Knockout 3.3.0 and Knockout Validation 2.0.3, focusing on validation after self.customer is assigned a new NewCustomer instance. Confirm the expected behavior for the grouped errors and identify a regression test or documented outcome for validation after replacement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.