billythekid / conditional-fields

Craft plugin to only use fields if certain conditions (other field values) match
MIT License
12 stars 1 forks source link

Add category/entries support #10

Closed askogrand closed 4 years ago

askogrand commented 4 years ago

Current conditions seem best suited to text, checkbox, or lightswitch fields. When using the conditional field with a category selection, the plugin treats the categories field as never containing a value, regardless of whether it has a selected one or many categories:

image

Is identical to:

image

Both evaluate as "No value (empty)"

billythekid commented 4 years ago

Thanks for this report.

Yeah I think that this makes sense, it should have a way of telling if it's an empty/non-empty value. I only really did the initial checks with lightbox fields, adding arrays(which the relational fields are) was done as an after thought and I think only the contains/does not contain options work for them at the moment.

Will hopefully get a fix for this out soon.

askogrand commented 4 years ago

Categories seems to output an empty value as a hidden field, regardless of whether the field has categories available. It also seems to leave no indication that the field in question is a category field.

<input type="hidden" name="fields[category]" value="">

It does, however, sit next to:

<div id="fields-category" class="categoriesfield">

Indicating that it is a categories field. I assume the same would be true for entries.

billythekid commented 4 years ago

@askogrand that's right, in the javascript I actually have two checks for values, one that holds an array of every field it finds and one with the 'first' value.

at the moment the empty/nonempty check only checks the 'single' value, which is exactly what you point out there, always empty (to reset the values if the items are removed)

Should be a super simple fix in the js for this, just check the other value instead of the first one.

I'm ignoring any indications of what the field types actually are, because I don't want to restrict it to built-in field types, it 'should' work with any field types theoretically. so I just go DOM scraping on the input page for the fields under the hood

billythekid commented 4 years ago

@askogrand that's 0.0.4 out with this fix (and another one I found off the back of this where plain text fields were simply ignored completely!)

Thanks again for your report.