craft-neo
craft-neo copied to clipboard
"Neo Block Condition" aren't dynamic
Description
New native Craft CMS condition doesn't work as expected on Neo blocks. A save (entry) is needed in order to fullfill the condition (ex. display a field if another field match the condition).
Steps to reproduce
- Add a block
- Add a trigger field
- Add a target field
- Link those fields with a condition
- Go to an entry where the Neo field is available
- Try the condition
Other information
- Neo version: 3.0.4
- Craft version: 4.0.2
Just having a quick look through the relevant Craft code and how it gets submitted/returned, I'm not confident that it's possible to do this yet; it seems to be set up to show/hide fields directly on the draft itself and not sub-fields of things like Neo blocks, unless I've missed something. If I didn't miss anything, then I assume it'll be possible for Neo to support this either when Matrix fields get full field layouts, or Craft Commerce products/variants get draft support.
@ttempleton Thanks for looking into this. Is this something that Craft will have to support and offer, if so this is something we can push for if there is not already an issue for it.
Is this something that Craft will have to support and offer
I think so, yeah. Looking at the code when saving drafts (PHP/JS) it's only tracking the status of the field layout elements directly on the draft element being saved, and doesn't look to be any way for something like Neo blocks/subfields to integrate with it (I'd definitely be happy to be proven wrong on this, though).
I am sure you are right and it maybe something which needs to be supported in Craft first with their nested blocks. Because there are plugins which already support this and are working very closely with Craft I wonder if there isn't a reason this could not be supported sooner rather than waiting for Craft 5. I will open an issue on Craft and we can see what happens from there
+1 from me on this! I'd find it an extremely useful tool for simplifying block configuration for clients if / when possible.
Not sure if this update for Craft 4.2.0 makes available, Matrix blocks are at least getting conditionals. https://github.com/craftcms/cms/commit/bc841350d57026806cd051f06488680be2dbbb9d
@zizther That adds the ability to set conditions based on whether Matrix fields are empty or not, there doesn't seem to be any conditions for Matrix sub-fields in Craft 4.2. I've just made the equivalent change for the next Neo release (https://github.com/spicywebau/craft-neo/commit/427bcac170a0e4e5c74c3fc9540157c2b642e7c9).
Every little helps 🙂
Confirming, I have this same issue. Just upgraded a dev site to 4.0.0 to test out and specifically leverage conditions in Neo blocks and saw this same issue. If you need a video, I did record one.
Would like to see this implemented as well.
Working on a block that gives the user three options for the header area (that make sense to the entry & the design):
- Brand logo
- Custom heading text
- Pre-defined text from the page
I was really hoping that the custom heading text field would only appear if this option was selected, but it's just persistently visible, I believe this is to do with this issue here, so giving context above as to what and where this is. This is something I'd love to see added.
Over the past couple of days, I've been looking into whether we could adapt Craft's code for setting a draft's visible field layout elements/tabs on draft save, to be used by Neo to update Neo blocks' visible layout elements/tabs after detecting a draft save. The result of this is in the enhancement/dynamic-block-conditions
branch, and will be released in the near future in Neo 3.7.0.
If anyone is willing to give that branch a try and provide any feedback, it would be greatly appreciated!
@ttempleton Sorry to bother you with this, but we are currently evaluating Neo blocks vs native Matrix fields for a project we are working on. Do you have an ETA for 3.7.0
? No dynamic conditions make for a poor UX for our non-technical editors, but we really like the other features Neo provides.
@r0skar It should be released later next week.
Neo 3.7.0 has just been released.
@ttempleton I'm still experiencing the original issue where a save is required before the condition is fulfilled.
If it helps, I am seeing the following response error from the neo/input/update-visible-elements
action:
error: "Call to a member function getFieldValue() on null"
To replicate:
- Add a block condition to fields based on a dropdown field:
- e.g., only show when:
My Dropdown Field
is one of
A
- For reference, I have one group of field to show when condition equals
A
and another group when condition equalsB
- e.g., only show when:
- Add a new entry or edit an existing (it fails in either case).
- Add the block that has this condition applied.
- Only the dropdown field is visible, as the dropdown field is initially rendered with a blank option. (Related discussion from Craft about this change introduced in version 4.4.)
- Select an option.
- Nothing happens until I save the entry.
Let me know if I can provide any other detail to help out.