{"action":"created","issue":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4946","repository_url":"https://api.github.com/repos/bcit-ci/CodeIgniter","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4946/labels{/name}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4946/comments","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4946/events","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4946","id":196020886,"number":4946,"title":"set_value for a multiselect uses $default, on form error, when everything in the multiselect was previously unchosen","user":{"login":"emilebourquin","id":89332,"avatar_url":"https://avatars.githubusercontent.com/u/89332?v=3","gravatar_id":"","url":"https://api.github.com/users/emilebourquin","html_url":"https://github.com/emilebourquin","followers_url":"https://api.github.com/users/emilebourquin/followers","following_url":"https://api.github.com/users/emilebourquin/following{/other_user}","gists_url":"https://api.github.com/users/emilebourquin/gists{/gist_id}","starred_url":"https://api.github.com/users/emilebourquin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emilebourquin/subscriptions","organizations_url":"https://api.github.com/users/emilebourquin/orgs","repos_url":"https://api.github.com/users/emilebourquin/repos","events_url":"https://api.github.com/users/emilebourquin/events{/privacy}","received_events_url":"https://api.github.com/users/emilebourquin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-16T09:56:56Z","updated_at":"2016-12-16T10:54:08Z","closed_at":null,"body":"I'm an old-school 2.x CodeIgniter user, in which set_value for a multiselect did not work at all, so kudos on getting set_value working for multiselect.\r\n\r\nI have an edit-user form in which there is a non-required host_owner multiselect. When I open the user for edit, and unchoose any default-chosen host_owners, and the form encounters an error upon submit, the default host_owners are still selected, because, of course, when a multiselect with nothing selected is POST'ed , nothing is actually POST'ed, much like an unchecked checkbox. Since nothing is POST'ed, the default $default_host_owners takes over. I need to be able to unselect all host_owners, and have that stick upon form errors.\r\n\r\nTo clarify:\r\n1) Click to edit a user\r\n2) host_owners[] multiselect has $default_host_owners selected\r\n2) Unselect all values of the host_owners[] multiselect\r\n3) Fail to fill out a required textbox, or some such error\r\n4) Click submit\r\n5) host_owners[] multiselect is back to having $default_host_owners selected\r\n\r\nHere's the line from the form:\r\n\r\n`<?= form_multiselect('host_owners[]', $host_owners, set_value('host_owners[]', $default_host_owners), 'id=inputHostOwners class=\"multiselect-host_owners\" size=\"10\"'); ?>`\r\n\r\nI've come up with a workaround in the controller to set $default_host_owners to NULL if $this->input->post() is true, but I also have a tentative fix for the form_helper's set_value function that I want to run by you;\r\n\r\nline 697 of system\\helpers\\form_helper.php (set_value function) is currently:\r\n\r\n`isset($value) OR $value = $default;`\r\n\r\nI have changed it to:\r\n\r\n`(isset($value) OR $CI->input->post()) OR $value = $default;`\r\n\r\nand it does the trick for my multiselect.\r\n\r\nDo you see any downsides? Is this something that could make its way into CodeIgniter?"},"comment":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/comments/267568961","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4946#issuecomment-267568961","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4946","id":267568961,"user":{"login":"narfbg","id":1058011,"avatar_url":"https://avatars.githubusercontent.com/u/1058011?v=3","gravatar_id":"","url":"https://api.github.com/users/narfbg","html_url":"https://github.com/narfbg","followers_url":"https://api.github.com/users/narfbg/followers","following_url":"https://api.github.com/users/narfbg/following{/other_user}","gists_url":"https://api.github.com/users/narfbg/gists{/gist_id}","starred_url":"https://api.github.com/users/narfbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narfbg/subscriptions","organizations_url":"https://api.github.com/users/narfbg/orgs","repos_url":"https://api.github.com/users/narfbg/repos","events_url":"https://api.github.com/users/narfbg/events{/privacy}","received_events_url":"https://api.github.com/users/narfbg/received_events","type":"User","site_admin":false},"created_at":"2016-12-16T10:54:08Z","updated_at":"2016-12-16T10:54:08Z","body":"I don't understand what you mean with that \"foreach'ing\" ... `set_select()` is what you're supposed to use here."}}
{"actor":{"display_login":"narfbg"}}