{"action":"opened","issue":{"url":"https://api.github.com/repos/aurelia/validation/issues/370","repository_url":"https://api.github.com/repos/aurelia/validation","labels_url":"https://api.github.com/repos/aurelia/validation/issues/370/labels{/name}","comments_url":"https://api.github.com/repos/aurelia/validation/issues/370/comments","events_url":"https://api.github.com/repos/aurelia/validation/issues/370/events","html_url":"https://github.com/aurelia/validation/issues/370","id":185087824,"number":370,"title":"Strange behavior for the validation binding behavior","user":{"login":"qraynaud","id":65991,"avatar_url":"https://avatars.githubusercontent.com/u/65991?v=3","gravatar_id":"","url":"https://api.github.com/users/qraynaud","html_url":"https://github.com/qraynaud","followers_url":"https://api.github.com/users/qraynaud/followers","following_url":"https://api.github.com/users/qraynaud/following{/other_user}","gists_url":"https://api.github.com/users/qraynaud/gists{/gist_id}","starred_url":"https://api.github.com/users/qraynaud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qraynaud/subscriptions","organizations_url":"https://api.github.com/users/qraynaud/orgs","repos_url":"https://api.github.com/users/qraynaud/repos","events_url":"https://api.github.com/users/qraynaud/events{/privacy}","received_events_url":"https://api.github.com/users/qraynaud/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-25T11:19:14Z","updated_at":"2016-10-25T11:19:14Z","closed_at":null,"body":"**I'm submitting a bug report**\r\n\r\n* **Library Version:**\r\n0.13.1\r\n\r\n\r\n**Please tell us about your environment:**\r\n* **Operating System:**\r\nLinux (KUbuntu 16.10)\r\n\r\n* **Node Version:**\r\n6.9.1\r\n\r\n* **NPM Version:**\r\n3.10.8\r\n\r\n* **Browser:**\r\nall\r\n\r\n* **Language:**\r\nall\r\n\r\n**Current behavior:**\r\n\r\nI split on multiple pages a big form to make it more usable. The routing changes on each page to allow to ref a specific part of the form with an URL. I have a simple service returning the object to be edited by the form either from cache or an API call for the first time.\r\n\r\nI'm using this validation rules for one of the page of my form:\r\n\r\n```js\r\nValidationRules\r\n  .ensure('username')\r\n    .required()\r\n    .minLength(4)\r\n  .ensure('firstname')\r\n    .required()\r\n    .minLength(4)\r\n  .ensure('lastname')\r\n    .required()\r\n    .minLength(4)\r\n  .ensure('email')\r\n    .required()\r\n    .email()\r\n  .on(User)\r\n;\r\n```\r\n\r\nI have the following view:\r\n\r\n```pug\r\ntemplate\r\n  form.form-horizontal(submit.delegate=\"user.save()\")\r\n    .form-group.has-feedback\r\n      label.col-sm-3.control-label(for=\"username\") Nom d'utilisateur\r\n      .col-sm-9\r\n        input.form-control(type=\"text\" id=\"username\" placeholder=\"Nom d'utilisateur\" value.bind=\"user.username & validate:controller\")\r\n    .form-group.has-feedback\r\n      label.col-sm-3.control-label(for=\"firstname\") Prénom\r\n      .col-sm-9\r\n        input.form-control(type=\"text\" id=\"firstname\" placeholder=\"Prénom\" value.bind=\"user.firstname & validate\")\r\n    .form-group.has-feedback\r\n      label.col-sm-3.control-label(for=\"lastname\") Nom\r\n      .col-sm-9\r\n        input.form-control(type=\"text\" id=\"lastname\" placeholder=\"Nom\" value.bind=\"user.lastname & validate\")\r\n    .form-group.has-feedback\r\n      label.col-sm-3.control-label(for=\"email\") Email\r\n      .col-sm-9\r\n        input.form-control(type=\"email\" id=\"email\" placeholder=\"Email\" value.bind=\"user.email & validate\")\r\n```\r\n\r\nAnd here is my model (simplified to only keep relevant code):\r\n```js\r\n@inject(UserCache, ValidationControllerFactory)\r\nexport class Edit {\r\n  constructor(userCache, controllerFactory) {\r\n    this.userCache = userCache;\r\n\r\n    this.controller = controllerFactory.createForCurrentScope();\r\n    this.controller.validateTrigger = validateTrigger.changeOrBlur;\r\n    this.controller.addRenderer(new BootstrapFormRenderer());\r\n  }\r\n\r\n  activate() {\r\n    return this.userCache.get('me')\r\n      .then(user => {\r\n        this.user = user;\r\n        this.controller.validate({object: user});\r\n      })\r\n    ;\r\n  }\r\n\r\n  deactivate() {\r\n    this.user = null;\r\n  }\r\n}\r\n```\r\n\r\nAs of now, when I change one of the field to empty it during edition, the rule triggers properly the required error message. If I change to a second page of my form, the controller goes into an error state because the user object comes from cache and has now a missing property.\r\n\r\nBut when I come back on the original form, the error is reset and the error message is not printed. I added some debug in the renderer and I can confirm reset instructions are sent for every binding behaviour.\r\n\r\nEven if I comment out the reset code, the controller does not seem to be able to relate the error to the correct binding and thus the error message is not displayed.\r\n\r\nAnother way to see this is to add `this.controller.addError('some message', this.user, 'firstname');` after the user is set in the activate promise. It is reseted right away. With resets commented out, it is never shown below the firstname field.\r\n\r\n**Expected/desired behavior**\r\n\r\n* **What is the expected behavior?**\r\n\r\nI believe there should be a way of setting an initial state in the controller to display error messages properly at form display.\r\n\r\n* **What is the motivation / use case for changing the behavior?**\r\n\r\nI know in normal conditions you should not have errors on a form at display time, but it happens that you want an user to correct a mistake and thus to display a form that properly points out where fixes are needed.\r\n\r\nAlso, I don't think errors added with `addError()` should be so casually trashed without an explicit `reset()` call from the validation lib user (me in this case) or `removeError()` call."}}
{"actor":{"display_login":"qraynaud"}}