Answers.Body: <p>In your FieldType you have <code>$this-&gt;element</code> available, representing the Element the field is in. If you use <code>$this-&gt;element-&gt;lightSwitchHandle</code> you can access its value.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T14:29:39.043Z
Answers.Text: Oh! So much simpler than I thought. I'd been scouting through Craft's code looking at ways to loop through the Entry's fields etc. Thanks. (Coincidentally, just as your answer popped up I was reading your Import plugin!)
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T15:08:50.383Z
Answers.Text: Although, having tried this... in order to ensure the Assets field is used when the Lightswitch is 'on', my custom field type needs to be a child of Lightswitch, and that needs to check the Assets field is set. I can't work out how to check if it has any Assets set.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T15:40:37.960Z
Answers.Text: I think I stumbled on the answer: `$this->element->[assetsHandle]->total()`.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T16:59:13.593Z
Answers.Text: That is correct
Answers.UserDisplayName: Bob Olde Hampsink
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T14:25:49.483Z
Answers.LastActivityDate: 2015-06-18T14:25:49.483Z
Answers.UserDisplayName: Bob Olde Hampsink
Body: <p>I have an Assets field which I want to be required only if a separate Lightswitch field on the same Entry is 'on'. I'm currently trying to implement this with a simple plugin that creates a custom field type (<a href="https://github.com/rally-agency/Craft-Unique-Text-FieldType" rel="nofollow">along these lines</a>).</p>
  
  <p>However, in my Field Type's <code>validation()</code> method I can't work out how to access the Lightswitch field's value on this same Entry, in order see if it's 'on' or not.</p>
  
Tags: <plugins><validation>
Title: A plugin to validate a field depending on another field's value
ThreadText: # A plugin to validate a field depending on another field's value
  
  (Asked by: username_0 on 2015-06-18)
  
  I have an Assets field which I want to be required only if a separate Lightswitch field on the same Entry is 'on'. I'm currently trying to implement this with a simple plugin that creates a custom field type ([along these lines](https://github.com/rally-agency/Craft-Unique-Text-FieldType)).
  
  However, in my Field Type's `validation()` method I can't work out how to access the Lightswitch field's value on this same Entry, in order see if it's 'on' or not.
  
  **Tags:** plugins, validation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-06-18. Score: 3 | Accepted answer
  
  In your FieldType you have `$this->element` available, representing the Element the field is in. If you use `$this->element->lightSwitchHandle` you can access its value.
  
  > **Comments:**
  > **username_0**: Oh! So much simpler than I thought. I'd been scouting through Craft's code looking at ways to loop through the Entry's fields etc. Thanks. (Coincidentally, just as your answer popped up I was reading your Import plugin!)  
  > **username_0**: Although, having tried this... in order to ensure the Assets field is used when the Lightswitch is 'on', my custom field type needs to be a child of Lightswitch, and that needs to check the Assets field is set. I can't work out how to check if it has any Assets set.  
  > **username_0**: I think I stumbled on the answer: `$this->element->[assetsHandle]->total()`.  
  > **username_1**: That is correct  
  
  ---
  
  