craft-neo icon indicating copy to clipboard operation
craft-neo copied to clipboard

"Neo Block Condition" aren't dynamic

Open jesuismaxime opened this issue 2 years ago • 11 comments

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

  1. Add a block
  2. Add a trigger field
  3. Add a target field
  4. Link those fields with a condition
  5. Go to an entry where the Neo field is available
  6. Try the condition

Other information

  • Neo version: 3.0.4
  • Craft version: 4.0.2

jesuismaxime avatar May 17 '22 13:05 jesuismaxime

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 avatar May 17 '22 14:05 ttempleton

@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.

zizther avatar Jun 15 '22 19:06 zizther

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).

ttempleton avatar Jun 16 '22 09:06 ttempleton

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

zizther avatar Jun 16 '22 09:06 zizther

+1 from me on this! I'd find it an extremely useful tool for simplifying block configuration for clients if / when possible.

tigerchick avatar Jul 12 '22 11:07 tigerchick

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 avatar Jul 26 '22 17:07 zizther

@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).

ttempleton avatar Jul 27 '22 02:07 ttempleton

Every little helps 🙂

zizther avatar Jul 27 '22 08:07 zizther

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.

jacksoncool avatar Aug 08 '22 19:08 jacksoncool

Would like to see this implemented as well.

plumduffer avatar Aug 09 '22 22:08 plumduffer

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.

JayBox325 avatar Aug 22 '22 14:08 JayBox325

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 avatar Jan 31 '23 04:01 ttempleton

@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 avatar Feb 16 '23 13:02 r0skar

@r0skar It should be released later next week.

ttempleton avatar Feb 17 '23 05:02 ttempleton

Neo 3.7.0 has just been released.

ttempleton avatar Feb 21 '23 05:02 ttempleton

@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 equals B
  • 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.

chrismlusk avatar Mar 13 '23 15:03 chrismlusk