How to validate dependent fields for a content type? In one of my content types I have 1 field 'venue' with a drop down option. If I select 'venue' as 'other' from the drop down, some other fields (say 'venue address' and 'venue name') should become required fields and the node should not be saved or updated if those required fields are empty.

This is the screenshot of the rule I created.



This is my rule in Rules export format:

{ "rules_schedule_program_venue" : {
    "LABEL" : "Schedule Program venue",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave--schedule_programs" : { "bundle" : "schedule_programs" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_venue" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_venue_address" } },
      { "data_is" : {
          "data" : [ "node:field-venue" ],
          "op" : "IN",
          "value" : { "value" : { "9" : "9" } }
        }
      },
      { "data_is_empty" : { "data" : [ "node:field-venue-address" ] } },
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "schedule_programs" : "schedule_programs" } }
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "address field is required",
          "type" : "error",
          "repeat" : "0"
        }
      }
    ]
  }
}


Please let me know what Rules Action I need to add to show an error message without updating or saving node.

I tried adding the Show a message on site action, but it is updating or saving the node anyway. I also tried with the Set an error on the form action, but in Data selector there isn't the field venue address.

Any other suggestion using javascript or jquery  to achieve this task is also fine.
Can anybody help me in using 'Rules Forms' module in this case?
I'm not aware of a way to get this to work using the Rules module. Because even if you use Rules Action "set a message" (of type = error) the node will still be saved. For more details on this, and/or possible work arounds, refer to my answer to "How to add a confirm dialog to node add and edit forms?".

If you really want to get this to work with Rules, a possible work around for your case might be to also use the Conditional Rules module, so that in your Rules Action you could "add a Rules Condition" (yes!) to check which option got selected for "venue". And if it is NOT "other", then within your Rules Action you set some dummy value (like "n.a."?) for "venue address" and "venue name".

Plan B

An alternative solution that you may want to experiment with (to see if it works in your case), is the Conditional Fields module. Excerpt from its project page:


  Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing and displayed if the state of the “dependee” field matches the right condition.
  
  When editing a node (or any other entity type that supports fields, like users and categories), the dependent fields are dynamically modified with the States API.
  
  You can, for example, define a custom “Article teaser" field that is shown only if a "Has teaser" checkbox is checked.