Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Parsing HTML wrong behaviour
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
I saw that all examples attach an "errors" property to an istance of a viewModel but I have a generic class which extends ViewModel
`Emi.G.Masters = kb.ViewModel.extend({...`
I have a viewModel with two observable. To check parseInputAttributes I set a required attribute in the javascript code and I used the HTML5 attribute "required" for the second one.
`this.title = ko.observable('').extend({required: true});`
`this.description = ko.observable('');`
And then, an istance of my class
`Emi.G.vm = new Emi.G.Masters;`
Now, if I attach errors to the istance
`Emi.G.vm.errors = ko.validation.group(Emi.G.vm);`
and in the submit I checked errors like this
`submit: function(self, e) {`
` if (self.errors().length != 0) {`
` self.errors.showAllMessages();`
` return;`
` }`
all works but if I create a class method
`errors: function() {`
` var self = this;`
` return ko.validation.group(self);`
`},`
and
`submit: function(self, e) {`
` if (self.errors()().length != 0) {`
` self.errors().showAllMessages();`
` return;`
` }`
self.errors()().length is correctly 2 but error messages appears only in the title field, the one extended. And if I filled title with some string, self.errors()().length was 1 but no message appears.
Contributor guide
Research direction
Start by reproducing the two cases from the issue: assigning ko.validation.group(Emi.G.vm) to errors versus returning it from the class method. Compare the validation group count and displayed messages after changing title and description; done means both required fields report and clear errors consistently.
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
- Needs clarification
- Newbie friendliness
- 30/100