{"action":"created","comment":{"url":"https://api.github.com/repos/adamwathan/form/pulls/comments/53504596","id":53504596,"diff_hunk":"@@ -76,11 +76,14 @@ protected function setChecked($checked = true)\n \n     protected function checkBinding()\n     {\n-        $currentValue = $this->getAttribute('value');\n+        $currentValue = (string) $this->getAttribute('value');","path":"src/AdamWathan/Form/Elements/Checkbox.php","position":5,"original_position":5,"commit_id":"1167327a4564c055b0a32e38946644f550a7bca9","original_commit_id":"1167327a4564c055b0a32e38946644f550a7bca9","user":{"login":"JesseLeite","id":5187394,"avatar_url":"https://avatars.githubusercontent.com/u/5187394?v=3","gravatar_id":"","url":"https://api.github.com/users/JesseLeite","html_url":"https://github.com/JesseLeite","followers_url":"https://api.github.com/users/JesseLeite/followers","following_url":"https://api.github.com/users/JesseLeite/following{/other_user}","gists_url":"https://api.github.com/users/JesseLeite/gists{/gist_id}","starred_url":"https://api.github.com/users/JesseLeite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JesseLeite/subscriptions","organizations_url":"https://api.github.com/users/JesseLeite/orgs","repos_url":"https://api.github.com/users/JesseLeite/repos","events_url":"https://api.github.com/users/JesseLeite/events{/privacy}","received_events_url":"https://api.github.com/users/JesseLeite/received_events","type":"User","site_admin":false},"body":"Sure man.  So at first `===` made sense to me, but then this happened.  I was minding my own business trying to implement simple radios with binary values...\r\n```\r\n$form->radio('published', 1)->render();\r\n$form->radio('published', 0)->render();\r\n```\r\n\r\nIn context of Laravel/Eloquent, these values are not cast to integers unless I setup an accessor on my model and intval() the thing.  However, the value stored on the field object is stored as integer.  So by default the old input provider shows the user's selected value as string, but the value on the element object is integer, causing this  `1 === \"1\"` to not bind the old input.\r\n\r\nThe problem is, we can't simple `1 == \"1\"`.  Imagine this scenario...\r\n```html\r\n<input type=\"radio\" name=\"published\" value=\"0\">\r\n```\r\n\r\nIf there is no old value ($oldValue on the field object is then `null`), then doing a `0 === null` equates to true, and the radio is checked, as if it were old input!  So in this case we DO WANT `===`, but in the first case we don't want `===`.\r\n\r\nCasting everything to string before comparing values solves both problems.  TL;DR... The HTML value attribute on checkboxes/radios know nothing about an integer, or anything about data types for that matter.  All it knows is string.  If we cast everything to string first, we get a more accurate comparison of old input.","created_at":"2016-02-19T19:18:48Z","updated_at":"2016-02-19T19:18:48Z","html_url":"https://github.com/adamwathan/form/pull/78#discussion_r53504596","pull_request_url":"https://api.github.com/repos/adamwathan/form/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/adamwathan/form/pulls/comments/53504596"},"html":{"href":"https://github.com/adamwathan/form/pull/78#discussion_r53504596"},"pull_request":{"href":"https://api.github.com/repos/adamwathan/form/pulls/78"}}},"pull_request":{"url":"https://api.github.com/repos/adamwathan/form/pulls/78","id":59843967,"html_url":"https://github.com/adamwathan/form/pull/78","diff_url":"https://github.com/adamwathan/form/pull/78.diff","patch_url":"https://github.com/adamwathan/form/pull/78.patch","issue_url":"https://api.github.com/repos/adamwathan/form/issues/78","number":78,"state":"open","locked":false,"title":"Fix checkbox array binding","user":{"login":"JesseLeite","id":5187394,"avatar_url":"https://avatars.githubusercontent.com/u/5187394?v=3","gravatar_id":"","url":"https://api.github.com/users/JesseLeite","html_url":"https://github.com/JesseLeite","followers_url":"https://api.github.com/users/JesseLeite/followers","following_url":"https://api.github.com/users/JesseLeite/following{/other_user}","gists_url":"https://api.github.com/users/JesseLeite/gists{/gist_id}","starred_url":"https://api.github.com/users/JesseLeite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JesseLeite/subscriptions","organizations_url":"https://api.github.com/users/JesseLeite/orgs","repos_url":"https://api.github.com/users/JesseLeite/repos","events_url":"https://api.github.com/users/JesseLeite/events{/privacy}","received_events_url":"https://api.github.com/users/JesseLeite/received_events","type":"User","site_admin":false},"body":"Old input and model binding worked fine multiple selects (this PR adds test coverage to prove this):\r\n```php\r\n$form->select('favourite_foods[]', array('fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'))->multiple()\r\n```\r\n\r\nBut doesn't work on checkbox arrays:\r\n```php\r\n$form->checkbox('favourite_foods[]', 'fish')\r\n$form->checkbox('favourite_foods[]', 'tofu')\r\n$form->checkbox('favourite_foods[]', 'chips')\r\n```\r\n\r\nThis PR adds test coverage and a proposed fix for checkbox array old input and model binding.","created_at":"2016-02-18T18:42:55Z","updated_at":"2016-02-19T19:18:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6bcb2f67ac781889334d6534b5ac5ffdc58c85d4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/adamwathan/form/pulls/78/commits","review_comments_url":"https://api.github.com/repos/adamwathan/form/pulls/78/comments","review_comment_url":"https://api.github.com/repos/adamwathan/form/pulls/comments{/number}","comments_url":"https://api.github.com/repos/adamwathan/form/issues/78/comments","statuses_url":"https://api.github.com/repos/adamwathan/form/statuses/1167327a4564c055b0a32e38946644f550a7bca9","head":{"label":"JesseLeite:fix-checkbox-array-binding","ref":"fix-checkbox-array-binding","sha":"1167327a4564c055b0a32e38946644f550a7bca9","user":{"login":"JesseLeite","id":5187394,"avatar_url":"https://avatars.githubusercontent.com/u/5187394?v=3","gravatar_id":"","url":"https://api.github.com/users/JesseLeite","html_url":"https://github.com/JesseLeite","followers_url":"https://api.github.com/users/JesseLeite/followers","following_url":"https://api.github.com/users/JesseLeite/following{/other_user}","gists_url":"https://api.github.com/users/JesseLeite/gists{/gist_id}","starred_url":"https://api.github.com/users/JesseLeite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JesseLeite/subscriptions","organizations_url":"https://api.github.com/users/JesseLeite/orgs","repos_url":"https://api.github.com/users/JesseLeite/repos","events_url":"https://api.github.com/users/JesseLeite/events{/privacy}","received_events_url":"https://api.github.com/users/JesseLeite/received_events","type":"User","site_admin":false},"repo":{"id":52029377,"name":"form","full_name":"JesseLeite/form","owner":{"login":"JesseLeite","id":5187394,"avatar_url":"https://avatars.githubusercontent.com/u/5187394?v=3","gravatar_id":"","url":"https://api.github.com/users/JesseLeite","html_url":"https://github.com/JesseLeite","followers_url":"https://api.github.com/users/JesseLeite/followers","following_url":"https://api.github.com/users/JesseLeite/following{/other_user}","gists_url":"https://api.github.com/users/JesseLeite/gists{/gist_id}","starred_url":"https://api.github.com/users/JesseLeite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JesseLeite/subscriptions","organizations_url":"https://api.github.com/users/JesseLeite/orgs","repos_url":"https://api.github.com/users/JesseLeite/repos","events_url":"https://api.github.com/users/JesseLeite/events{/privacy}","received_events_url":"https://api.github.com/users/JesseLeite/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JesseLeite/form","description":"Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.","fork":true,"url":"https://api.github.com/repos/JesseLeite/form","forks_url":"https://api.github.com/repos/JesseLeite/form/forks","keys_url":"https://api.github.com/repos/JesseLeite/form/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JesseLeite/form/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JesseLeite/form/teams","hooks_url":"https://api.github.com/repos/JesseLeite/form/hooks","issue_events_url":"https://api.github.com/repos/JesseLeite/form/issues/events{/number}","events_url":"https://api.github.com/repos/JesseLeite/form/events","assignees_url":"https://api.github.com/repos/JesseLeite/form/assignees{/user}","branches_url":"https://api.github.com/repos/JesseLeite/form/branches{/branch}","tags_url":"https://api.github.com/repos/JesseLeite/form/tags","blobs_url":"https://api.github.com/repos/JesseLeite/form/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JesseLeite/form/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JesseLeite/form/git/refs{/sha}","trees_url":"https://api.github.com/repos/JesseLeite/form/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JesseLeite/form/statuses/{sha}","languages_url":"https://api.github.com/repos/JesseLeite/form/languages","stargazers_url":"https://api.github.com/repos/JesseLeite/form/stargazers","contributors_url":"https://api.github.com/repos/JesseLeite/form/contributors","subscribers_url":"https://api.github.com/repos/JesseLeite/form/subscribers","subscription_url":"https://api.github.com/repos/JesseLeite/form/subscription","commits_url":"https://api.github.com/repos/JesseLeite/form/commits{/sha}","git_commits_url":"https://api.github.com/repos/JesseLeite/form/git/commits{/sha}","comments_url":"https://api.github.com/repos/JesseLeite/form/comments{/number}","issue_comment_url":"https://api.github.com/repos/JesseLeite/form/issues/comments{/number}","contents_url":"https://api.github.com/repos/JesseLeite/form/contents/{+path}","compare_url":"https://api.github.com/repos/JesseLeite/form/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JesseLeite/form/merges","archive_url":"https://api.github.com/repos/JesseLeite/form/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JesseLeite/form/downloads","issues_url":"https://api.github.com/repos/JesseLeite/form/issues{/number}","pulls_url":"https://api.github.com/repos/JesseLeite/form/pulls{/number}","milestones_url":"https://api.github.com/repos/JesseLeite/form/milestones{/number}","notifications_url":"https://api.github.com/repos/JesseLeite/form/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JesseLeite/form/labels{/name}","releases_url":"https://api.github.com/repos/JesseLeite/form/releases{/id}","deployments_url":"https://api.github.com/repos/JesseLeite/form/deployments","created_at":"2016-02-18T18:35:23Z","updated_at":"2016-02-18T18:35:24Z","pushed_at":"2016-02-18T19:42:59Z","git_url":"git://github.com/JesseLeite/form.git","ssh_url":"git@github.com:JesseLeite/form.git","clone_url":"https://github.com/JesseLeite/form.git","svn_url":"https://github.com/JesseLeite/form","homepage":null,"size":189,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"adamwathan:master","ref":"master","sha":"4a264739ffe15d1917133d80e35973ce7bbde207","user":{"login":"adamwathan","id":4323180,"avatar_url":"https://avatars.githubusercontent.com/u/4323180?v=3","gravatar_id":"","url":"https://api.github.com/users/adamwathan","html_url":"https://github.com/adamwathan","followers_url":"https://api.github.com/users/adamwathan/followers","following_url":"https://api.github.com/users/adamwathan/following{/other_user}","gists_url":"https://api.github.com/users/adamwathan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamwathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamwathan/subscriptions","organizations_url":"https://api.github.com/users/adamwathan/orgs","repos_url":"https://api.github.com/users/adamwathan/repos","events_url":"https://api.github.com/users/adamwathan/events{/privacy}","received_events_url":"https://api.github.com/users/adamwathan/received_events","type":"User","site_admin":false},"repo":{"id":12576720,"name":"form","full_name":"adamwathan/form","owner":{"login":"adamwathan","id":4323180,"avatar_url":"https://avatars.githubusercontent.com/u/4323180?v=3","gravatar_id":"","url":"https://api.github.com/users/adamwathan","html_url":"https://github.com/adamwathan","followers_url":"https://api.github.com/users/adamwathan/followers","following_url":"https://api.github.com/users/adamwathan/following{/other_user}","gists_url":"https://api.github.com/users/adamwathan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamwathan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamwathan/subscriptions","organizations_url":"https://api.github.com/users/adamwathan/orgs","repos_url":"https://api.github.com/users/adamwathan/repos","events_url":"https://api.github.com/users/adamwathan/events{/privacy}","received_events_url":"https://api.github.com/users/adamwathan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adamwathan/form","description":"Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.","fork":false,"url":"https://api.github.com/repos/adamwathan/form","forks_url":"https://api.github.com/repos/adamwathan/form/forks","keys_url":"https://api.github.com/repos/adamwathan/form/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adamwathan/form/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adamwathan/form/teams","hooks_url":"https://api.github.com/repos/adamwathan/form/hooks","issue_events_url":"https://api.github.com/repos/adamwathan/form/issues/events{/number}","events_url":"https://api.github.com/repos/adamwathan/form/events","assignees_url":"https://api.github.com/repos/adamwathan/form/assignees{/user}","branches_url":"https://api.github.com/repos/adamwathan/form/branches{/branch}","tags_url":"https://api.github.com/repos/adamwathan/form/tags","blobs_url":"https://api.github.com/repos/adamwathan/form/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adamwathan/form/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adamwathan/form/git/refs{/sha}","trees_url":"https://api.github.com/repos/adamwathan/form/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adamwathan/form/statuses/{sha}","languages_url":"https://api.github.com/repos/adamwathan/form/languages","stargazers_url":"https://api.github.com/repos/adamwathan/form/stargazers","contributors_url":"https://api.github.com/repos/adamwathan/form/contributors","subscribers_url":"https://api.github.com/repos/adamwathan/form/subscribers","subscription_url":"https://api.github.com/repos/adamwathan/form/subscription","commits_url":"https://api.github.com/repos/adamwathan/form/commits{/sha}","git_commits_url":"https://api.github.com/repos/adamwathan/form/git/commits{/sha}","comments_url":"https://api.github.com/repos/adamwathan/form/comments{/number}","issue_comment_url":"https://api.github.com/repos/adamwathan/form/issues/comments{/number}","contents_url":"https://api.github.com/repos/adamwathan/form/contents/{+path}","compare_url":"https://api.github.com/repos/adamwathan/form/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adamwathan/form/merges","archive_url":"https://api.github.com/repos/adamwathan/form/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adamwathan/form/downloads","issues_url":"https://api.github.com/repos/adamwathan/form/issues{/number}","pulls_url":"https://api.github.com/repos/adamwathan/form/pulls{/number}","milestones_url":"https://api.github.com/repos/adamwathan/form/milestones{/number}","notifications_url":"https://api.github.com/repos/adamwathan/form/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adamwathan/form/labels{/name}","releases_url":"https://api.github.com/repos/adamwathan/form/releases{/id}","deployments_url":"https://api.github.com/repos/adamwathan/form/deployments","created_at":"2013-09-03T22:46:18Z","updated_at":"2016-02-18T16:07:20Z","pushed_at":"2016-02-18T19:42:59Z","git_url":"git://github.com/adamwathan/form.git","ssh_url":"git@github.com:adamwathan/form.git","clone_url":"https://github.com/adamwathan/form.git","svn_url":"https://github.com/adamwathan/form","homepage":null,"size":238,"stargazers_count":103,"watchers_count":103,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"open_issues_count":8,"forks":41,"open_issues":8,"watchers":103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/adamwathan/form/pulls/78"},"html":{"href":"https://github.com/adamwathan/form/pull/78"},"issue":{"href":"https://api.github.com/repos/adamwathan/form/issues/78"},"comments":{"href":"https://api.github.com/repos/adamwathan/form/issues/78/comments"},"review_comments":{"href":"https://api.github.com/repos/adamwathan/form/pulls/78/comments"},"review_comment":{"href":"https://api.github.com/repos/adamwathan/form/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/adamwathan/form/pulls/78/commits"},"statuses":{"href":"https://api.github.com/repos/adamwathan/form/statuses/1167327a4564c055b0a32e38946644f550a7bca9"}}}}