{"action":"created","issue":{"url":"https://api.github.com/repos/formly-js/angular-formly/issues/527","labels_url":"https://api.github.com/repos/formly-js/angular-formly/issues/527/labels{/name}","comments_url":"https://api.github.com/repos/formly-js/angular-formly/issues/527/comments","events_url":"https://api.github.com/repos/formly-js/angular-formly/issues/527/events","html_url":"https://github.com/formly-js/angular-formly/issues/527","id":113648105,"number":527,"title":"updateInitialValue doesn't work with complex keys","user":{"login":"eliagentili","id":1882869,"avatar_url":"https://avatars.githubusercontent.com/u/1882869?v=3","gravatar_id":"","url":"https://api.github.com/users/eliagentili","html_url":"https://github.com/eliagentili","followers_url":"https://api.github.com/users/eliagentili/followers","following_url":"https://api.github.com/users/eliagentili/following{/other_user}","gists_url":"https://api.github.com/users/eliagentili/gists{/gist_id}","starred_url":"https://api.github.com/users/eliagentili/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliagentili/subscriptions","organizations_url":"https://api.github.com/users/eliagentili/orgs","repos_url":"https://api.github.com/users/eliagentili/repos","events_url":"https://api.github.com/users/eliagentili/events{/privacy}","received_events_url":"https://api.github.com/users/eliagentili/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-27T18:16:04Z","updated_at":"2015-10-30T13:31:45Z","closed_at":null,"body":"I noticed that the updateInitialValue doesn't work if you define a complex key in your formly form.\r\n\r\nThis not work:\r\n```\r\nform: {\r\n          options: {},\r\n          model: this.model,\r\n          fields: [\r\n            {\r\n              key: 'FieldParent.value',\r\n              type: 'input',\r\n              templateOptions: {\r\n                label: 'FieldOne'\r\n              }\r\n            }\r\n          ]\r\n        }\r\n      }\r\n```\r\n\r\nSo, if the key is something like Field.value, or maybe more sub-index, it doesn't work.\r\nWorks only with simple key like \"field\".\r\n\r\nThis Work:\r\n```\r\nform: {\r\n          options: {},\r\n          model: this.model,\r\n          fields: [\r\n            {\r\n              key: 'field',\r\n              type: 'input',\r\n              templateOptions: {\r\n                label: 'FieldOne'\r\n              }\r\n            }\r\n          ]\r\n        }\r\n      }\r\n```\r\n\r\nI think it's useful to handling sub-index in form keys, maybe editing:\r\nsrc/directives/formly-field.js:182\r\ncan fix the problem."},"comment":{"url":"https://api.github.com/repos/formly-js/angular-formly/issues/comments/152526914","html_url":"https://github.com/formly-js/angular-formly/issues/527#issuecomment-152526914","issue_url":"https://api.github.com/repos/formly-js/angular-formly/issues/527","id":152526914,"user":{"login":"kentcdodds","id":1500684,"avatar_url":"https://avatars.githubusercontent.com/u/1500684?v=3","gravatar_id":"","url":"https://api.github.com/users/kentcdodds","html_url":"https://github.com/kentcdodds","followers_url":"https://api.github.com/users/kentcdodds/followers","following_url":"https://api.github.com/users/kentcdodds/following{/other_user}","gists_url":"https://api.github.com/users/kentcdodds/gists{/gist_id}","starred_url":"https://api.github.com/users/kentcdodds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kentcdodds/subscriptions","organizations_url":"https://api.github.com/users/kentcdodds/orgs","repos_url":"https://api.github.com/users/kentcdodds/repos","events_url":"https://api.github.com/users/kentcdodds/events{/privacy}","received_events_url":"https://api.github.com/users/kentcdodds/received_events","type":"User","site_admin":false},"created_at":"2015-10-30T13:31:45Z","updated_at":"2015-10-30T13:31:45Z","body":"No, the real solution is to set the value using the $parse service. We do\nthis for default values.\n\nOn Fri, Oct 30, 2015, 6:19 AM MCKRUZ <notifications@github.com> wrote:\n\n> I believe this is related to the same issue I'm having with model\n> resetting. Here is what I think is happening.\n>\n> function resetModel() {\n> $scope.model[$scope.options.key] = $scope.options.initialValue;\n> if ($scope.options.formControl) {\n> if (_angularFix2['default'].isArray($scope.options.formControl)) {\n> _angularFix2['default'].forEach($scope.options.formControl, function\n> (formControl) {\n> resetFormControl(formControl, true);\n> });\n> } else {\n> resetFormControl($scope.options.formControl);\n> }\n> }\n> }\n>\n> Inside this code block we set $scope.model[$scope.options.key] like so.\n> Unfortunately if you have a key that is dot delimited it doesn't find the\n> value. We should be using some sort of recursive find like this one.\n>\n> function _setNested(path, value, obj) {\n> var schema = obj; // a moving reference to internal objects within obj\n> var pList = path.split('.');\n> var len = pList.length;\n> for (var i = 0; i < len - 1; i++) {\n> var elem = pList[i];\n> if (!schema[elem]) schema[elem] = {}\n> schema = schema[elem];\n> }\n>\n>         schema[pList[len - 1]] = value;\n>     }\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/formly-js/angular-formly/issues/527#issuecomment-152522247>\n> .\n>\n-- \n- Kent C. Dodds <https://twitter.com/kentcdodds>\n"}}