{"action":"created","issue":{"url":"https://api.github.com/repos/formly-js/angular-formly/issues/555","labels_url":"https://api.github.com/repos/formly-js/angular-formly/issues/555/labels{/name}","comments_url":"https://api.github.com/repos/formly-js/angular-formly/issues/555/comments","events_url":"https://api.github.com/repos/formly-js/angular-formly/issues/555/events","html_url":"https://github.com/formly-js/angular-formly/issues/555","id":118418090,"number":555,"title":"Field hidden with hideExpression unaccessible after being shown","user":{"login":"zorzysty","id":5398733,"avatar_url":"https://avatars.githubusercontent.com/u/5398733?v=3","gravatar_id":"","url":"https://api.github.com/users/zorzysty","html_url":"https://github.com/zorzysty","followers_url":"https://api.github.com/users/zorzysty/followers","following_url":"https://api.github.com/users/zorzysty/following{/other_user}","gists_url":"https://api.github.com/users/zorzysty/gists{/gist_id}","starred_url":"https://api.github.com/users/zorzysty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zorzysty/subscriptions","organizations_url":"https://api.github.com/users/zorzysty/orgs","repos_url":"https://api.github.com/users/zorzysty/repos","events_url":"https://api.github.com/users/zorzysty/events{/privacy}","received_events_url":"https://api.github.com/users/zorzysty/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-23T16:27:05Z","updated_at":"2015-12-03T16:29:45Z","closed_at":"2015-12-03T16:29:45Z","body":"I've got a field which must be hidden until a REST response says otherwise.\r\nThat's the code I use:\r\n```\r\nid: \"nameInput\",\r\nhideExpression: function () {\r\n  return !vm.model.nameRequired\r\n}\r\n```\r\nOn recieving certain REST response,  (1.) the field must be shown, (2.) set to required and (3.) required validation ng-message must be displayed.\r\n\r\nHere's my code:\r\n\r\n**In field description:**\r\n```\r\nexpressionProperties: {\r\n    \"templateOptions.required\": function () {\r\n        return vm.model.nameRequired\r\n    }\r\n}\r\n```\r\n**After REST promise is resolved:**\r\n```\r\nvm.model.nameRequired = true;\r\nvm.form.nameInput.$setTouched();\r\n```\r\n\r\nThe problem is that ```vm.form.nameInput``` is undefined at this point.\r\n\r\nHow can I invoke $setTouched() after the field is instantiated and it's object accessible?\r\n\r\n**EDIT:**\r\nIt works when I wrap it with $timeout:\r\n```\r\nvm.model.nameRequired = true;\r\n$timeout(function () {\r\n    vm.form.nameInput.$setTouched();\r\n});\r\n```\r\nBut that's pretty ugly hack and doesn't work well with Protractor E2E tests."},"comment":{"url":"https://api.github.com/repos/formly-js/angular-formly/issues/comments/161706258","html_url":"https://github.com/formly-js/angular-formly/issues/555#issuecomment-161706258","issue_url":"https://api.github.com/repos/formly-js/angular-formly/issues/555","id":161706258,"user":{"login":"benoror","id":119117,"avatar_url":"https://avatars.githubusercontent.com/u/119117?v=3","gravatar_id":"","url":"https://api.github.com/users/benoror","html_url":"https://github.com/benoror","followers_url":"https://api.github.com/users/benoror/followers","following_url":"https://api.github.com/users/benoror/following{/other_user}","gists_url":"https://api.github.com/users/benoror/gists{/gist_id}","starred_url":"https://api.github.com/users/benoror/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoror/subscriptions","organizations_url":"https://api.github.com/users/benoror/orgs","repos_url":"https://api.github.com/users/benoror/repos","events_url":"https://api.github.com/users/benoror/events{/privacy}","received_events_url":"https://api.github.com/users/benoror/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T16:29:45Z","updated_at":"2015-12-03T16:29:45Z","body":"Do you mind creating an example of what you're trying to accomplish? Please follow the instructions here: http://help.angular-formly.com\r\n\r\nThis will make it easier for you to get help. Because the github issues are reserved for bug reports and feature requests, I'm going to go ahead and close this issue. See you on chat! Thanks!\r\n"}}