Knockout-Contrib / Knockout-Contrib/Knockout-Validation

Knockout Validation doesn't work on initial load if mapping plugin is called twice

Open
#152 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

circle back
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

I posted this to StackOverflow as well. If there is an answer there, I will update this issue.

This one has been causing me grief for a while.

I have a web app that uses Knockout, Knockout Mapping, and Knockout Validation. Everything is going pretty well except for this problem. The problem is demonstrated by this Fiddle: http://jsfiddle.net/bmccord/eMHdH/.

To demonstrate the problem, run the fiddle and then select something from the list. When it comes up, clear out the Name field. You may or may not see the validation message (it is random. On fiddle it seems never to show when first running but in my actual code, it sometimes does and sometimes doesn't when refreshing the page).

Now click on the reload button and do the same thing again. This time you should see the validation error.

Now for the really fun part. At the bottom of the javascript, comment out the line that says:

self.loadSupportData();
This is just to keep the second mapping from running. Try the experiment again. This time the validation will work on initial run.

What is causing this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked JSFiddle and reproduce the validation behavior after selecting an item, clearing Name, and reloading. Compare the run where self.loadSupportData() triggers a second mapping with the run where that line is commented out. Done means identifying why the initial validation state differs and documenting or correcting the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.