<p>You can use a <a href="https://docs.craftcms.com/v3/element-types.html#relations" rel="nofollow noreferrer">Relation Field</a> for each of your element types and include a custom js rule so if one of them has a value, the other one can't be selected. </p>

<p>The more difficult way would be to extend the field and the <code>ElementSelectModal</code> and the <code>ElementIndex</code> to select multiple element types but this is going to be a little bit more tricky since you'll need a custom controller to fetch all elements and can't rely on the <code>ElementsController</code></p>

CC BY-SA 4.0
2018-06-22T19:30:04.897Z
Is there a similar feature on craft 2?
juanmrad
CC BY-SA 4.0
2018-06-22T19:53:52.680Z
Yes there is the same field just with slightly different logic
Robin Schambach
CC BY-SA 4.0
2018-06-22T20:03:33.573Z
Haven't been able to found the equivalent.
juanmrad
CC BY-SA 4.0
2018-06-22T20:12:20.557Z
Take a look at `craft/app/fieldtypes/EntriesFieldType` and the class it extends
Robin Schambach
CC BY-SA 4.0
2018-06-25T14:23:33.657Z
So I create a new FieldType that Extends `BaseElementFieldType` ? and the class should be on both plugins under the folder fieldtype? something like: `Plugin1_TestFieldType` and `Plugin2_TestFieldType` ?
juanmrad
CC BY-SA 4.0
2018-06-25T14:26:15.050Z
Yeah, As I said, you can take a look at `craft/app/fieldtypes/EntriesFieldType` all you need to do is to change the `protected $elementType = 'Entry';` to your custom Element type. Each for your elements will have their custom field type. You can then include JS somewhere that checks if both field types exists and if so remove the content from the other one on select
Robin Schambach
CC BY-SA 4.0
2018-06-25T14:30:43.613Z
ok. so I will have two different Fields and then I have to add some custom JS to check and avoid the selection of both.
juanmrad
CC BY-SA 4.0
2018-06-22T19:06:56.907Z
2018-06-22T19:06:56.907Z
Robin Schambach
<p>I have 2 plugins I created that store similar data:</p>

<p>Plugin 1: <code>id, name, panel_id, price</code></p>

<p>Plugin 2: <code>id, name, test_id, price</code></p>

<p>I want to attach my plugin data to an entry, and I need to make sure they can only select one Panel or Test. I want to know if there is a way to add them as a source for Entries as a new field. Or can I create a similar custom fieldtype to be used for both plugins and have that kind of validation?</p>

<p>I'm using Craft V2.6</p>

<plugin-development><plugins><fieldtypes><custom-fieldtype><custom>
Custom Pluging Entries FieldType
# Custom Pluging Entries FieldType

(Asked by: username_0 on 2018-06-22)

I have 2 plugins I created that store similar data:

Plugin 1: `id, name, panel_id, price`

Plugin 2: `id, name, test_id, price`

I want to attach my plugin data to an entry, and I need to make sure they can only select one Panel or Test. I want to know if there is a way to add them as a source for Entries as a new field. Or can I create a similar custom fieldtype to be used for both plugins and have that kind of validation?

I'm using Craft V2.6

**Tags:** plugin-development, plugins, fieldtypes, custom-fieldtype, custom


---

## 1 answers

### Answer by username_1 on 2018-06-22. Score: 1

You can use a [Relation Field](https://docs.craftcms.com/v3/element-types.html#relations) for each of your element types and include a custom js rule so if one of them has a value, the other one can't be selected.

The more difficult way would be to extend the field and the `ElementSelectModal` and the `ElementIndex` to select multiple element types but this is going to be a little bit more tricky since you'll need a custom controller to fetch all elements and can't rely on the `ElementsController`

> **Comments:**
> **username_0**: Is there a similar feature on craft 2?  
> **username_1**: Yes there is the same field just with slightly different logic  
> **username_0**: Haven't been able to found the equivalent.  
> **username_1**: Take a look at `craft/app/fieldtypes/EntriesFieldType` and the class it extends  
> **username_0**: So I create a new FieldType that Extends `BaseElementFieldType` ? and the class should be on both plugins under the folder fieldtype? something like: `Plugin1_TestFieldType` and `Plugin2_TestFieldType` ?  
> **username_1**: Yeah, As I said, you can take a look at `craft/app/fieldtypes/EntriesFieldType` all you need to do is to change the `protected $elementType = 'Entry';` to your custom Element type. Each for your elements will have their custom field type. You can then include JS somewhere that checks if both field types exists and if so remove the content from the other one on select  
> **username_0**: ok. so I will have two different Fields and then I have to add some custom JS to check and avoid the selection of both.  

---

