{"action":"created","issue":{"url":"https://api.github.com/repos/moneyadviceservice/dough/issues/223","labels_url":"https://api.github.com/repos/moneyadviceservice/dough/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/moneyadviceservice/dough/issues/223/comments","events_url":"https://api.github.com/repos/moneyadviceservice/dough/issues/223/events","html_url":"https://github.com/moneyadviceservice/dough/pull/223","id":62738956,"number":223,"title":"Add validation error prefix","user":{"login":"neoeno","id":1007202,"avatar_url":"https://avatars.githubusercontent.com/u/1007202?v=3","gravatar_id":"","url":"https://api.github.com/users/neoeno","html_url":"https://github.com/neoeno","followers_url":"https://api.github.com/users/neoeno/followers","following_url":"https://api.github.com/users/neoeno/following{/other_user}","gists_url":"https://api.github.com/users/neoeno/gists{/gist_id}","starred_url":"https://api.github.com/users/neoeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neoeno/subscriptions","organizations_url":"https://api.github.com/users/neoeno/orgs","repos_url":"https://api.github.com/users/neoeno/repos","events_url":"https://api.github.com/users/neoeno/events{/privacy}","received_events_url":"https://api.github.com/users/neoeno/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-18T16:45:27Z","updated_at":"2015-03-19T10:12:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/moneyadviceservice/dough/pulls/223","html_url":"https://github.com/moneyadviceservice/dough/pull/223","diff_url":"https://github.com/moneyadviceservice/dough/pull/223.diff","patch_url":"https://github.com/moneyadviceservice/dough/pull/223.patch"},"body":"This PR makes the form validation functionality, across both ruby and JS, use the form ID when generating the IDs for error labels. If there's no form ID (such as when we're using `fields_for` in a form) it falls back to `object_name`.\r\n\r\nSo, in the case of Ruby, instead of `#error-1`, we get `#error-form_id-1`.\r\n\r\nAnd, in the case of JS, instead of `#error-field_name` we get `#error-form_id-field_name`.\r\n\r\nThis helps us avoid duplicate IDs (and links to those IDs) when we have more than one form on the same page.\r\n\r\nBackground, from slack:\r\n\r\n> __Caden Lovelace:__\r\n> I'm working on a form with `fields_for`. Both the form and the `fields_for` use `Dough::Forms::Builders::Validation`. And they both use `form#validation_summary` to display errors\r\n> And each error in the validation summary has an ID link, like `#error-1` to link to the individual error fields\r\n> But the validation summary in the `fields_for` starts again at `#error-1`, which means it links to the first error in the parent form. The in-form validations also start again, at `#error-1`, so we get duplicate IDs too.\r\n> Is there an established way of dealing with this situation?\r\n> e.g.  \r\n> ![image](https://cloud.githubusercontent.com/assets/1007202/6713885/150e2db4-cd8d-11e4-9410-be6b4514c2e0.png)\r\n\r\n> __Phil Lee__\r\n> I can't see a workaround. A change could be made to dough to accept a string/namespce into the form builder which could be prefixed to the error id\r\n\r\nI thought using the form ID with a fallback to the object name _might_ be better than adding an attribute to the form, but I'm not completely happy with this either. Any thoughts/alternative ideas are welcome."},"comment":{"url":"https://api.github.com/repos/moneyadviceservice/dough/issues/comments/83480210","html_url":"https://github.com/moneyadviceservice/dough/pull/223#issuecomment-83480210","issue_url":"https://api.github.com/repos/moneyadviceservice/dough/issues/223","id":83480210,"user":{"login":"asmega","id":92580,"avatar_url":"https://avatars.githubusercontent.com/u/92580?v=3","gravatar_id":"","url":"https://api.github.com/users/asmega","html_url":"https://github.com/asmega","followers_url":"https://api.github.com/users/asmega/followers","following_url":"https://api.github.com/users/asmega/following{/other_user}","gists_url":"https://api.github.com/users/asmega/gists{/gist_id}","starred_url":"https://api.github.com/users/asmega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asmega/subscriptions","organizations_url":"https://api.github.com/users/asmega/orgs","repos_url":"https://api.github.com/users/asmega/repos","events_url":"https://api.github.com/users/asmega/events{/privacy}","received_events_url":"https://api.github.com/users/asmega/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T10:12:56Z","updated_at":"2015-03-19T10:12:56Z","body":":+1: "}}