<p>Unlike structured entries, when you relate a category to another element, its ancestors are also included in the relation. Due to <a href="http://buildwithcraft.com/classreference/services/CategoriesService#fillGapsInCategoryIds-detail" rel="nofollow">the way Craft looks up these ancestors when relating the selected categories, to enforce this behaviour</a>, the ancestors are added to the relation <em>before</em> the one you selected, and it looks like you're limiting that Categories field to <strong>1</strong>, so <em>only</em> the parent is being added.</p>

<p>Try setting the limit on that Categories field to <strong>2</strong>.</p>

CC BY-SA 3.0
2015-09-03T12:10:59.183Z
2015-09-03T12:10:59.183Z
Mike Pepper
<p>I have a Structure section <code>fruit</code> with a single entry type <code>fruit</code>. </p>

<p>I also have a Category <code>fruitType</code> with 2 levels: </p>

<ul>
<li>Citrus

<ul>
<li>Orange</li>
<li>Lemon</li>
<li>Lime</li>
</ul></li>
<li>Melons

<ul>
<li>Watermelon</li>
<li>Honeydew</li>
</ul></li>
</ul>

<p>The entry type <code>fruit</code> has a Category field for <code>fruitType</code>. </p>

<p>If I select a level 2 category for the <code>fruitType</code> field, say <code>Orange</code>: </p>

<p><a href="https://i.sstatic.net/fjMbi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fjMbi.png" alt="Category Selection"></a></p>

<p>Craft CMS dismisses the category selection pop-up and the parent category is shown instead, in this case <code>Citrus</code>. </p>

<p><a href="https://i.sstatic.net/GiyDD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GiyDD.png" alt="Resulting Category"></a></p>

<p>From the browser's network inspector, I noticed that a POST request to <code>/admin/actions/elements/getCategoriesInputHtml</code> with the following form data: </p>

<pre><code>categoryIds[]:893
locale:en_us
id:fields-fruitCategory
name:fields[fruitCategory]
limit:1
selectionLabel:Category
</code></pre>

<p>However, the response from the server is: </p>

<pre><code>{"html":"&lt;input type=\"hidden\" name=\"fields[fruitCategory]\" value=\"\"&gt;\n\n&lt;div id=\"fields-fruitCategory\" class=\"categoriesfield\"&gt;\n\t&lt;ul class=\"elements structure\"&gt;\n\t\t\t\t\t&lt;li id=\"fields-fruitCategory-category-887\"&gt;\n\t\t\t\t\t\t\t\t&lt;div class=\"row\" style=\"margin-left: -0px; padding-left: 0px;\"&gt;&lt;div class=\"element removable\" data-id=\"887\" data-locale=\"en_us\" data-status=\"enabled\" data-label=\"Faculty\" data-url=\"http:\/\/craft.local\/fruit\/citrus\" data-level=\"1\" data-editable&gt;&lt;input type=\"hidden\" name=\"fields[fruitCategory][]\" value=\"887\"&gt;&lt;a class=\"delete icon\" title=\"Remove\"&gt;&lt;\/a&gt; &lt;div class=\"label\"&gt;&lt;span class=\"status enabled\"&gt;&lt;\/span&gt;&lt;span class=\"title\"&gt;Citrus&lt;\/span&gt;&lt;\/div&gt;&lt;\/div&gt;&lt;\/div&gt;\n\n\t\t\t\t\t\t\t&lt;\/li&gt;\n\t\t\t&lt;\/ul&gt;\n\n\t&lt;div class=\"btn add icon dashed\"&gt;Category&lt;\/div&gt;\n&lt;\/div&gt;\n\n"}
</code></pre>

<p>Based on the response and what's rendered in the interface, Citrus is shown and not Orange, despite Orange being selected.</p>

<categories><field>
Cannot select subcategory field in entity
# Cannot select subcategory field in entity

(Asked by: username_0 on 2015-09-03)

I have a Structure section fruit with a single entry type fruit. 
I also have a Category fruitType with 2 levels: 

Citrus


Orange
Lemon
Lime

Melons


Watermelon
Honeydew


The entry type fruit has a Category field for fruitType. 
If I select a level 2 category for the fruitType field, say Orange: 

Craft CMS dismisses the category selection pop-up and the parent category is shown instead, in this case Citrus. 

From the browser's network inspector, I noticed that a POST request to /admin/actions/elements/getCategoriesInputHtml with the following form data: 
categoryIds[]:893
locale:en_us
id:fields-fruitCategory
name:fields[fruitCategory]
limit:1
selectionLabel:Category

However, the response from the server is: 
{"html":"\n\n\n\t\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t<\/a> <\/span>Citrus<\/span><\/div><\/div><\/div>\n\n\t\t\t\t\t\t\t<\/li>\n\t\t\t<\/ul>\n\n\tCategory<\/div>\n<\/div>\n\n"}

Based on the response and what's rendered in the interface, Citrus is shown and not Orange, despite Orange being selected.

**Tags:** categories, field


---

## 1 answers

### Answer by username_1 on 2015-09-03. Score: 4 | Accepted answer

Unlike structured entries, when you relate a category to another element, its ancestors are also included in the relation. Due to [the way Craft looks up these ancestors when relating the selected categories, to enforce this behaviour](http://buildwithcraft.com/classreference/services/CategoriesService#fillGapsInCategoryIds-detail), the ancestors are added to the relation *before* the one you selected, and it looks like you're limiting that Categories field to **1**, so *only* the parent is being added.

Try setting the limit on that Categories field to **2**.


---

