unclecheese / silverstripe-display-logic

The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior.
BSD 3-Clause "New" or "Revised" License
74 stars 71 forks source link

Issue with some field names #109

Open robingram opened 4 years ago

robingram commented 4 years ago

Using dev-master on SS 4.4.

Bit of a strange one this and I was wracking my brains for about a day before I got an idea of what was going on.

We have a DataObject with a number of fields that use Display Logic. Two of these are ListboxField controls that use displayIf to control their visibility based on the value of an OptionsetField (not the same option set, different for each list box). The code to create these fields is virtually identical but for one of them the list box would never display on page load, although it would show based on the click, i.e. if I changed the option and then changed it back.

The best I could get from debugging is that the onmatch event for $('div.display-logic-master :checkbox, div.display-logic-master :radio') would not fire for this particular control, although it would for the other.

In desperation I started trying different things and eventually I renamed the DB field that was being referenced by displayIf and suddenly it started working. For some reason the code did not like the original name of the field which was "CanViewType". As far as I know this isn't a reserved word but it seemed to be affecting how Display Logic worked.

We've written a migration to change the field name so we've worked around it but thought you should be aware of this since it took me a looooong time to track down.

GuySartorelli commented 4 years ago

Do you happen to remember what the name was of the field that this wasn't working for?

robingram commented 4 years ago

Only from reading back my previous post. Looks like it was "CanViewType".

michalkleiner commented 1 year ago

My guess is there's some custom JS within the CMS itself using this particular field which then interferes with Display Logic.