{"action":"created","comment":{"url":"https://api.github.com/repos/adhocteam/fml/pulls/comments/23554588","id":23554588,"diff_hunk":"@@ -40,35 +47,99 @@ def initialize(field, data, form)\n       # strip the ! if there was one\n       data = data[1..-1] if @negative\n \n-      @child = field\n+      @field = field\n       @parent = form.fields[data]\n     end\n \n+    def conforms!\n+      if [\"yes_no\", \"checkbox\"].index(@parent.type).nil?\n+        raise InvalidSpec.new(<<-EOM)\n+Field #{@field.name} depends on field #{@parent.name}, which is not a boolean.\n+Fields may only depend on \"yes_no\" or \"checkbox\" fields, but #{@parent.name} is a\n+\"#{@parent.type}\" field.\n+      EOM\n+      end\n+    end\n+\n+    def required?\n+      @parent.visible? && (@parent.value) == @required\n+    end\n+\n+    def valid?\n+      !(required? && @field.empty?)\n+    end\n+\n     def validate\n       # if parent is @required, child must be non-empty. Note that @parent is\n       # required to be a boolean element, so we don't need to worry about \"\"\n       # being a truthy value\n-      if @parent.value == @required && @child.empty?\n+      if not valid?\n         debug_message = <<-EOM\n-Field #{@child.name}:#{@child.value.inspect} must be present when #{@parent.name}:#{@parent.value.inspect} is #{@required}\n+Field #{@field.name}:#{@field.value.inspect} must be present when #{@parent.name}:#{@parent.value.inspect} is #{@required}\n         EOM\n         user_message = \"This field is required\"\n-        err = DependencyError.new(user_message, debug_message, @child.name, @parent.name)\n-        @child.errors << err\n+        err = DependencyError.new(user_message, debug_message, @field.name, @parent.name)\n+        @field.errors << err\n         raise err\n       end\n     end\n   end\n \n-  class MinLengthValidation\n+  class RequiredIfTextEquals < BaseValidation\n     def initialize(field, data, form)\n       @field = field\n-      @minlength = data\n+      @wanted_values = Array(data['value'] || data['values'])\n+      @parent = form.fields[data['field']]\n+    end\n+\n+    def conforms!\n+      if [\"select\", \"text\"].index(@parent.type).nil?\n+        raise InvalidSpec.new(<<-EOM)\n+Field #{@field.name} depends on field #{@parent.name}, which is not a boolean.\n+Fields may only depend on \"select\" or \"text\" fields, but #{@parent.name} is a\n+\"#{@parent.type}\" field.\n+      EOM\n+      end\n+    end\n+\n+    def required?\n+      @wanted_values.include?(@parent.value)\n+    end\n+\n+    def valid?\n+      !(required? && @field.empty?)\n     end\n \n     def validate\n+      if not valid?\n+        debug_message = <<-EOM\n+Field #{@field.name}:#{@field.value.inspect} must be #{@wanted_values}\n+        EOM\n+        user_message = \"when #{@parent.name} is '#{@wanted_values}', #{@field.name} must be filled in\"\n+        err = ValidationError.new(user_message, debug_message, @field.name)\n+        @field.errors << err\n+        raise err\n+      end\n+    end\n+  end\n+\n+  class MinLengthValidation < BaseValidation\n+    def initialize(field, data, form)\n+      @field = field\n+      @minlength = data\n+    end\n+\n+    def required?\n+      false","path":"lib/fml_forms/validations.rb","position":114,"original_position":114,"commit_id":"79481ee6669411ab8d8647c749e3942212b6852e","original_commit_id":"79481ee6669411ab8d8647c749e3942212b6852e","user":{"login":"llimllib","id":7150,"avatar_url":"https://avatars.githubusercontent.com/u/7150?v=3","gravatar_id":"","url":"https://api.github.com/users/llimllib","html_url":"https://github.com/llimllib","followers_url":"https://api.github.com/users/llimllib/followers","following_url":"https://api.github.com/users/llimllib/following{/other_user}","gists_url":"https://api.github.com/users/llimllib/gists{/gist_id}","starred_url":"https://api.github.com/users/llimllib/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/llimllib/subscriptions","organizations_url":"https://api.github.com/users/llimllib/orgs","repos_url":"https://api.github.com/users/llimllib/repos","events_url":"https://api.github.com/users/llimllib/events{/privacy}","received_events_url":"https://api.github.com/users/llimllib/received_events","type":"User","site_admin":false},"body":"Why `false`?","created_at":"2015-01-26T18:57:34Z","updated_at":"2015-01-26T18:57:34Z","html_url":"https://github.com/adhocteam/fml/pull/2#discussion_r23554588","pull_request_url":"https://api.github.com/repos/adhocteam/fml/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/comments/23554588"},"html":{"href":"https://github.com/adhocteam/fml/pull/2#discussion_r23554588"},"pull_request":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/adhocteam/fml/pulls/2","id":26801742,"html_url":"https://github.com/adhocteam/fml/pull/2","diff_url":"https://github.com/adhocteam/fml/pull/2.diff","patch_url":"https://github.com/adhocteam/fml/pull/2.patch","issue_url":"https://api.github.com/repos/adhocteam/fml/issues/2","number":2,"state":"open","locked":false,"title":"ConditionalOn can apply to more than just boolean fields","user":{"login":"markolson","id":137988,"avatar_url":"https://avatars.githubusercontent.com/u/137988?v=3","gravatar_id":"","url":"https://api.github.com/users/markolson","html_url":"https://github.com/markolson","followers_url":"https://api.github.com/users/markolson/followers","following_url":"https://api.github.com/users/markolson/following{/other_user}","gists_url":"https://api.github.com/users/markolson/gists{/gist_id}","starred_url":"https://api.github.com/users/markolson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markolson/subscriptions","organizations_url":"https://api.github.com/users/markolson/orgs","repos_url":"https://api.github.com/users/markolson/repos","events_url":"https://api.github.com/users/markolson/events{/privacy}","received_events_url":"https://api.github.com/users/markolson/received_events","type":"User","site_admin":false},"body":"https://www.pivotaltracker.com/n/projects/1096074/stories/79793246\r\n* Extends conditionalOn logic to use the same classes that validations use, only for display logic.\r\n* Adds .visible? method to fields\r\n* Adds textEquals conditionalOn","created_at":"2015-01-05T00:15:45Z","updated_at":"2015-01-26T18:57:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0224b66d9b31670edc4fb1c8cecf2b2ca2b5b0ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/adhocteam/fml/pulls/2/commits","review_comments_url":"https://api.github.com/repos/adhocteam/fml/pulls/2/comments","review_comment_url":"https://api.github.com/repos/adhocteam/fml/pulls/comments/{number}","comments_url":"https://api.github.com/repos/adhocteam/fml/issues/2/comments","statuses_url":"https://api.github.com/repos/adhocteam/fml/statuses/79481ee6669411ab8d8647c749e3942212b6852e","head":{"label":"adhocteam:conditionalOn","ref":"conditionalOn","sha":"79481ee6669411ab8d8647c749e3942212b6852e","user":{"login":"adhocteam","id":6809738,"avatar_url":"https://avatars.githubusercontent.com/u/6809738?v=3","gravatar_id":"","url":"https://api.github.com/users/adhocteam","html_url":"https://github.com/adhocteam","followers_url":"https://api.github.com/users/adhocteam/followers","following_url":"https://api.github.com/users/adhocteam/following{/other_user}","gists_url":"https://api.github.com/users/adhocteam/gists{/gist_id}","starred_url":"https://api.github.com/users/adhocteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adhocteam/subscriptions","organizations_url":"https://api.github.com/users/adhocteam/orgs","repos_url":"https://api.github.com/users/adhocteam/repos","events_url":"https://api.github.com/users/adhocteam/events{/privacy}","received_events_url":"https://api.github.com/users/adhocteam/received_events","type":"Organization","site_admin":false},"repo":{"id":21440139,"name":"fml","full_name":"adhocteam/fml","owner":{"login":"adhocteam","id":6809738,"avatar_url":"https://avatars.githubusercontent.com/u/6809738?v=3","gravatar_id":"","url":"https://api.github.com/users/adhocteam","html_url":"https://github.com/adhocteam","followers_url":"https://api.github.com/users/adhocteam/followers","following_url":"https://api.github.com/users/adhocteam/following{/other_user}","gists_url":"https://api.github.com/users/adhocteam/gists{/gist_id}","starred_url":"https://api.github.com/users/adhocteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adhocteam/subscriptions","organizations_url":"https://api.github.com/users/adhocteam/orgs","repos_url":"https://api.github.com/users/adhocteam/repos","events_url":"https://api.github.com/users/adhocteam/events{/privacy}","received_events_url":"https://api.github.com/users/adhocteam/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/adhocteam/fml","description":"","fork":false,"url":"https://api.github.com/repos/adhocteam/fml","forks_url":"https://api.github.com/repos/adhocteam/fml/forks","keys_url":"https://api.github.com/repos/adhocteam/fml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adhocteam/fml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adhocteam/fml/teams","hooks_url":"https://api.github.com/repos/adhocteam/fml/hooks","issue_events_url":"https://api.github.com/repos/adhocteam/fml/issues/events{/number}","events_url":"https://api.github.com/repos/adhocteam/fml/events","assignees_url":"https://api.github.com/repos/adhocteam/fml/assignees{/user}","branches_url":"https://api.github.com/repos/adhocteam/fml/branches{/branch}","tags_url":"https://api.github.com/repos/adhocteam/fml/tags","blobs_url":"https://api.github.com/repos/adhocteam/fml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adhocteam/fml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adhocteam/fml/git/refs{/sha}","trees_url":"https://api.github.com/repos/adhocteam/fml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adhocteam/fml/statuses/{sha}","languages_url":"https://api.github.com/repos/adhocteam/fml/languages","stargazers_url":"https://api.github.com/repos/adhocteam/fml/stargazers","contributors_url":"https://api.github.com/repos/adhocteam/fml/contributors","subscribers_url":"https://api.github.com/repos/adhocteam/fml/subscribers","subscription_url":"https://api.github.com/repos/adhocteam/fml/subscription","commits_url":"https://api.github.com/repos/adhocteam/fml/commits{/sha}","git_commits_url":"https://api.github.com/repos/adhocteam/fml/git/commits{/sha}","comments_url":"https://api.github.com/repos/adhocteam/fml/comments{/number}","issue_comment_url":"https://api.github.com/repos/adhocteam/fml/issues/comments/{number}","contents_url":"https://api.github.com/repos/adhocteam/fml/contents/{+path}","compare_url":"https://api.github.com/repos/adhocteam/fml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adhocteam/fml/merges","archive_url":"https://api.github.com/repos/adhocteam/fml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adhocteam/fml/downloads","issues_url":"https://api.github.com/repos/adhocteam/fml/issues{/number}","pulls_url":"https://api.github.com/repos/adhocteam/fml/pulls{/number}","milestones_url":"https://api.github.com/repos/adhocteam/fml/milestones{/number}","notifications_url":"https://api.github.com/repos/adhocteam/fml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adhocteam/fml/labels{/name}","releases_url":"https://api.github.com/repos/adhocteam/fml/releases{/id}","created_at":"2014-07-02T20:56:30Z","updated_at":"2015-01-13T18:08:11Z","pushed_at":"2015-01-13T18:08:10Z","git_url":"git://github.com/adhocteam/fml.git","ssh_url":"git@github.com:adhocteam/fml.git","clone_url":"https://github.com/adhocteam/fml.git","svn_url":"https://github.com/adhocteam/fml","homepage":null,"size":753,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"adhocteam:master","ref":"master","sha":"b563af98541679ddac9bb8e9221a74e1bb1f864a","user":{"login":"adhocteam","id":6809738,"avatar_url":"https://avatars.githubusercontent.com/u/6809738?v=3","gravatar_id":"","url":"https://api.github.com/users/adhocteam","html_url":"https://github.com/adhocteam","followers_url":"https://api.github.com/users/adhocteam/followers","following_url":"https://api.github.com/users/adhocteam/following{/other_user}","gists_url":"https://api.github.com/users/adhocteam/gists{/gist_id}","starred_url":"https://api.github.com/users/adhocteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adhocteam/subscriptions","organizations_url":"https://api.github.com/users/adhocteam/orgs","repos_url":"https://api.github.com/users/adhocteam/repos","events_url":"https://api.github.com/users/adhocteam/events{/privacy}","received_events_url":"https://api.github.com/users/adhocteam/received_events","type":"Organization","site_admin":false},"repo":{"id":21440139,"name":"fml","full_name":"adhocteam/fml","owner":{"login":"adhocteam","id":6809738,"avatar_url":"https://avatars.githubusercontent.com/u/6809738?v=3","gravatar_id":"","url":"https://api.github.com/users/adhocteam","html_url":"https://github.com/adhocteam","followers_url":"https://api.github.com/users/adhocteam/followers","following_url":"https://api.github.com/users/adhocteam/following{/other_user}","gists_url":"https://api.github.com/users/adhocteam/gists{/gist_id}","starred_url":"https://api.github.com/users/adhocteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adhocteam/subscriptions","organizations_url":"https://api.github.com/users/adhocteam/orgs","repos_url":"https://api.github.com/users/adhocteam/repos","events_url":"https://api.github.com/users/adhocteam/events{/privacy}","received_events_url":"https://api.github.com/users/adhocteam/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/adhocteam/fml","description":"","fork":false,"url":"https://api.github.com/repos/adhocteam/fml","forks_url":"https://api.github.com/repos/adhocteam/fml/forks","keys_url":"https://api.github.com/repos/adhocteam/fml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adhocteam/fml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adhocteam/fml/teams","hooks_url":"https://api.github.com/repos/adhocteam/fml/hooks","issue_events_url":"https://api.github.com/repos/adhocteam/fml/issues/events{/number}","events_url":"https://api.github.com/repos/adhocteam/fml/events","assignees_url":"https://api.github.com/repos/adhocteam/fml/assignees{/user}","branches_url":"https://api.github.com/repos/adhocteam/fml/branches{/branch}","tags_url":"https://api.github.com/repos/adhocteam/fml/tags","blobs_url":"https://api.github.com/repos/adhocteam/fml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adhocteam/fml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adhocteam/fml/git/refs{/sha}","trees_url":"https://api.github.com/repos/adhocteam/fml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adhocteam/fml/statuses/{sha}","languages_url":"https://api.github.com/repos/adhocteam/fml/languages","stargazers_url":"https://api.github.com/repos/adhocteam/fml/stargazers","contributors_url":"https://api.github.com/repos/adhocteam/fml/contributors","subscribers_url":"https://api.github.com/repos/adhocteam/fml/subscribers","subscription_url":"https://api.github.com/repos/adhocteam/fml/subscription","commits_url":"https://api.github.com/repos/adhocteam/fml/commits{/sha}","git_commits_url":"https://api.github.com/repos/adhocteam/fml/git/commits{/sha}","comments_url":"https://api.github.com/repos/adhocteam/fml/comments{/number}","issue_comment_url":"https://api.github.com/repos/adhocteam/fml/issues/comments/{number}","contents_url":"https://api.github.com/repos/adhocteam/fml/contents/{+path}","compare_url":"https://api.github.com/repos/adhocteam/fml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adhocteam/fml/merges","archive_url":"https://api.github.com/repos/adhocteam/fml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adhocteam/fml/downloads","issues_url":"https://api.github.com/repos/adhocteam/fml/issues{/number}","pulls_url":"https://api.github.com/repos/adhocteam/fml/pulls{/number}","milestones_url":"https://api.github.com/repos/adhocteam/fml/milestones{/number}","notifications_url":"https://api.github.com/repos/adhocteam/fml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adhocteam/fml/labels{/name}","releases_url":"https://api.github.com/repos/adhocteam/fml/releases{/id}","created_at":"2014-07-02T20:56:30Z","updated_at":"2015-01-13T18:08:11Z","pushed_at":"2015-01-13T18:08:10Z","git_url":"git://github.com/adhocteam/fml.git","ssh_url":"git@github.com:adhocteam/fml.git","clone_url":"https://github.com/adhocteam/fml.git","svn_url":"https://github.com/adhocteam/fml","homepage":null,"size":753,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/2"},"html":{"href":"https://github.com/adhocteam/fml/pull/2"},"issue":{"href":"https://api.github.com/repos/adhocteam/fml/issues/2"},"comments":{"href":"https://api.github.com/repos/adhocteam/fml/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/adhocteam/fml/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/adhocteam/fml/statuses/79481ee6669411ab8d8647c749e3942212b6852e"}}}}