Issue with the word 'content' when filtering

I’m not even sure if this is a Kirby issue but I’m at a bit of a loss with it. I have four categories: “Design”, “Strategy”, “Content”, and “Code”. I’ve built a filter that uses JS to return results based on the URL parameter and it all works fine except for the “Content” filter. I know “content” is a protected word in Kirby, but I don’t think that’s what’s causing the issue. Is there a problem with using the word ‘content’ as a parameter on an input? I can’t find any info about that.

Here is how I’m creating the checkboxes

<?php
$items = ['Design','Strategy','Content','Code'];
foreach($items as $item): ?>
<label class="radio" for="<?= Str::slug($item) ?>">
    <input type="checkbox" id="<?= Str::slug($item) ?>" name="categories[]" value="<?= $item ?>" <?php if($ucategories){e(in_array($item, $ucategories), 'checked');}; e(!in_array($item, $acategories), 'disabled'); ?>>
    <div class="radio__label">
        <span><?= $item ?></span>
    </div>
</label>
<?php endforeach ?>

I’m using a multiselect field which adds the correct tags to the content file, eg.:

Categories: Design, Code, Content

And I get the parameters like this in JS:

const formData = new URLSearchParams(new FormData(form)).toString();
let url = `${window.location.href.split('?')[0]}.json?${formData}`;
let pushurl = `${window.location.href.split('?')[0]}?${formData}`;

Everything works as expected except “Content”. If I change everything to “Contents”, it works, but that’s not what I need it to be. Does this word need escaping somewhere? Has anyone came across this issue before? Am I going mad?

Edit: Also, if I add the category straight to the URL, it works and filters correctly…

projects?view=case-studies&categories%5B%5D=Content

If the direct access to the correct URL works, the filtering you do on the backend seems to work. So I feel this must originate from the frontend code. Which URL is generated when the “Content” category is selected?

Nothing actually happens with I click the “Content” checkbox. I’m detecting those events with a listener form.addEventListener('change', fetchArticles); which works for everything except ‘Content’. My code is a very modified version of this: Load more with Ajax | Kirby CMS

Ok, definitely not a Kirby issue, it seems like the issue is with clicking a label to activate the input:

Works:
image

Works but does not work for ‘Content’:
image

The actual HTML of the content input looks fine, but maybe there’s an issue with the label for=content?

<label class="radio" for="content">
    <input type="checkbox" id="content" name="categories[]" value="Content">
    <div class="radio__label">
        <span>Content</span>
    </div>
</label>

I can’t find any information about this anywhere though, if “content” is a protected word in an attribute value. For now I’ve just added a “category-” prefix to the forand ìd`attributes.

It could be that you have another element on the page with the ID content. Each ID value can only appear once on the page.

Turns out that is actually the case :sweat_smile: Can an entire thread be deleted out of embarrassment?

Don’t worry, that’s how debugging is sometimes. Glad you got it working :slight_smile:

1 Like