{"action":"created","issue":{"url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/294","repository_url":"https://api.github.com/repos/json-schema-form/angular-schema-form","labels_url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/294/labels{/name}","comments_url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/294/comments","events_url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/294/events","html_url":"https://github.com/json-schema-form/angular-schema-form/pull/294","id":60600355,"number":294,"title":"Enhance the select field with null value support","user":{"login":"ulion","id":175133,"avatar_url":"https://avatars.githubusercontent.com/u/175133?v=3","gravatar_id":"","url":"https://api.github.com/users/ulion","html_url":"https://github.com/ulion","followers_url":"https://api.github.com/users/ulion/followers","following_url":"https://api.github.com/users/ulion/following{/other_user}","gists_url":"https://api.github.com/users/ulion/gists{/gist_id}","starred_url":"https://api.github.com/users/ulion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ulion/subscriptions","organizations_url":"https://api.github.com/users/ulion/orgs","repos_url":"https://api.github.com/users/ulion/repos","events_url":"https://api.github.com/users/ulion/events{/privacy}","received_events_url":"https://api.github.com/users/ulion/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/json-schema-form/angular-schema-form/labels/type:%20bug","name":"type: bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2015-03-11T02:20:37Z","updated_at":"2016-09-25T15:14:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/json-schema-form/angular-schema-form/pulls/294","html_url":"https://github.com/json-schema-form/angular-schema-form/pull/294","diff_url":"https://github.com/json-schema-form/angular-schema-form/pull/294.diff","patch_url":"https://github.com/json-schema-form/angular-schema-form/pull/294.patch"},"body":"Angular's select with ngOptions has 3 type about the null value (the value=\"\" options). reference: https://docs.angularjs.org/api/ng/directive/ngOptions\r\n\r\n1. current angular-schema-form default implement, which will add a empty value options which result null by default if the model value does not match any enum/titleMap value and be selected by default. but once user selected any non-empty value, that empty value option is gone, which make the user have to make a choice but without a default selection if the field is also required.\r\n\r\n2. if put an option value=\"\" tag in the select tag, the empty option will be there like the previous type, except that the empty option won't get disappeared after user selected other option, so it make the null value always an option.\r\n\r\n3. if put an invisible option value=\"\", even with ng-if=\"false\", it will never populate an empty option, the select will have the first option selected if the model value does not match any option value.\r\n\r\nSo, above 3 type of use cases are all useful, but current angular-schema-form implement only give use the first use case support. This PR will add the later 2 type of select/ng-options support, so we can do with the null value better in many use cases.\r\n\r\ne.g. \r\n\r\n- for a select field, the null value is a valid option, and we want it always selectable, then we should make the schema type be ['null', 'string'], and use any following methods:\r\n   1. schema use enum, without titleMap. Then should put null as one of the possible value in the enum (if use enum schema, because tv4 will validate the value to the enum value list, so if use enum, null should be in the enum), this will make the null value always selectable. if want non-blank label for null value option, set form's allowAutoNullOption property for the select field to the label text you want.\r\n   2. schema use enum, with titleMap. Same as above, except the code will auto detect the titleMap (array type titleMap only) with the null value, if found, will auto use the name found as the null value option label (code internally auto setup allowAutoNullOption to the label), while you can still override it by set allowAutoNullOption to value you want.\r\n   3. schema not use enum, with titleMap (array type titleMap only). same as above, code will detect the null value label and auto setup allowAutoNullOption to the label text.\r\n\r\n- some times, you do not want a default empty option, you want the first option be selected by default, it can also be done by this PR, just set the form property allowAutoNullOption of the select field to false will do that.\r\n\r\n- There are also some rare cased, you want null value but not be the first option, for such use case, this PR can still do that, by set allowAutoNullOption to false, and include the null value in enum or your titleMap at the prefered position will simply do it."},"comment":{"url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/comments/249427239","html_url":"https://github.com/json-schema-form/angular-schema-form/pull/294#issuecomment-249427239","issue_url":"https://api.github.com/repos/json-schema-form/angular-schema-form/issues/294","id":249427239,"user":{"login":"Anthropic","id":1182507,"avatar_url":"https://avatars.githubusercontent.com/u/1182507?v=3","gravatar_id":"","url":"https://api.github.com/users/Anthropic","html_url":"https://github.com/Anthropic","followers_url":"https://api.github.com/users/Anthropic/followers","following_url":"https://api.github.com/users/Anthropic/following{/other_user}","gists_url":"https://api.github.com/users/Anthropic/gists{/gist_id}","starred_url":"https://api.github.com/users/Anthropic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anthropic/subscriptions","organizations_url":"https://api.github.com/users/Anthropic/orgs","repos_url":"https://api.github.com/users/Anthropic/repos","events_url":"https://api.github.com/users/Anthropic/events{/privacy}","received_events_url":"https://api.github.com/users/Anthropic/received_events","type":"User","site_admin":false},"created_at":"2016-09-25T15:14:08Z","updated_at":"2016-09-25T15:14:08Z","body":"@davidlgj any chance you can find a moment to fill me in on how far you got with this one?"}}
{"actor":{"display_login":"Anthropic"}}