Using drupal 8.7.7, conditional_fields 8.x-1.0-alpha6

When I create a dependency for a content type to be *required it does not show in the form display with a red asterisk nor does it enforce the dependency rule. I am including two (2) screenshots to help explain my problem. Setting the new dependency img_1, and after applying this new condition it fails to display and work properly img_2 as seen here on the form display in content creation mode.

this problem does not exist in conditional_fields 8.x-1.0-alpha5

Comments

fndtn357 created an issue. See original summary.

EmiliaC’s picture

StatusFileSize
new1.67 KB

Seems like the patch from https://www.drupal.org/project/conditional_fields/issues/2859667 could not be applied from alpha5 to alpha6 because it was missing the base file conditional_fields.api.inc which is now transformed into the class ConditionalFieldsFormHelper.
I re-applied to /src/ConditionalFieldsFormHelper.php the patch that cslevy provided.
Please review and advise if it ok.

EmiliaC’s picture

Status: Active » Needs review
visualnotion’s picture

Thank you for the patch.

I have tried it and it shows the asterisk and the attributes on my select field are marked as "required", but I can still submit the form without a making a selection in that field.

It appears to look fine, but just doesn't validate.

super_romeo’s picture

Status: Needs review » Needs work
megha_kundar’s picture

Status: Needs work » Needs review
StatusFileSize
new797 bytes

I have applied patch #2 and found that validation for that form is working fine. But, I could not find the asterisk symbol in the target field when the controlled field is checked. I have solved this issue by this modifying below js file and not sure whether this is the correct way please review this patch.

megha_kundar’s picture

StatusFileSize
new763 bytes
kris77’s picture

I don't know if it can help, but I noticed something.

I have my content type with two field: Field_1 is boolean and Field_2 is term reference with checkbox widget.

So, I have set as "required" Field_1 and Field_2 too. In "Manage Dependencies" I have set only one condition:

  • Field_2 is visible if Field_1 has value "ON"

Now, when create my content, if Field_1 is set to OFF and click on SAVE the node is create without problem. If Field_1 is set to ON, Field_2 is visible and asterisk is show too. If click on SAVE the node is NOT create and error message appears.

So, it seems that it is not necessary to set the condition required in "Manage Dependencies"

Steven McCoy’s picture

StatusFileSize
new807 bytes

This is my first time contributing, so please be gentle ;)

I modified the patch from #7, mainly to also add / remove the "required" attribute on the field, instead of just adding the flag to the label.

While I was in there, I also simplified some repetition with the jQuery references and the use of $.each

Steven McCoy’s picture

I've created a patch that toggles the required state of the field, in addition to just updating the label.

Additionally it makes for slightly cleaner and more performant jQuery calls.

ultrabob’s picture

Steven McCoy, thanks for your efforts on this. I haven't reviewed with any depth, but can confirm that the required asterisks show up where they should, they also show up in an unusual place: the text formatting selection. In a normal form those don't get a required asterisk, but they do after applying that patch.

ultrabob’s picture

StatusFileSize
new839 bytes

Here is a new version of #9 with an updated selector to avoid affecting formatting labels.

ultrabob’s picture

I'm a fairly new contributor too, and I'm having trouble understanding the output of those test fails. I'll try to dig in and figure it out on my own if time allows, but if anybody has some guidance on what specifically to look at, I'd be grateful. I see one test that the body field is visible failing, which shouldn't have anything to do with the change I made, or the patch I based mine on.

Main thing I don't understand is how #7 passed but mine and the previous one have errors that almost seem to be about how the test is written.

Update: I can only surmise that the test fails that have popped up since the last patch that passes all tests, are at least partially due to changes in the module code unrelated to these fixes, and the patch is working properly for me, so unless I hear back, I'll probably set this aside for now.

JvE’s picture

StatusFileSize
new857 bytes
super_romeo’s picture

I have multiple field (cardinality 3). And all 3 field inputs are required, but should be only first. E.g. <input name="field_phone[0][value]" ...>

I think my addition is a dirty way. I guess a better way to look at which field inputs are required from initial page load and change attributes only of those inputs.

sashken2’s picture

Patch #15 works very good. Thanks!

paulocs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new48.91 KB

Patch #15 looks good to me.
I didn't understand the problem from comment #16. Maybe @super_romeo can write the steps to reproduce.

kris77’s picture

Patch #15 works fine for me too.

Thanks @JvE

thalles’s picture

Assigned: Unassigned » thalles

  • thalles committed 181026c on 8.x-1.x authored by super_romeo
    Issue #3084387 by Megha_kundar, super_romeo, ultrabob, EmiliaC, Steven...
thalles’s picture

Fixed in dev branch!
Thanks @all!

thalles’s picture

Assigned: thalles » Unassigned
thalles’s picture

Status: Reviewed & tested by the community » Fixed
sashken2’s picture

thalles, why you committed patch #16 but not #15?

thalles’s picture

Thanks @sashken2!

  • thalles committed ed23bee on 8.x-1.x
    Revert "Issue #3084387 by Megha_kundar, super_romeo, ultrabob, EmiliaC,...
  • thalles committed ed7ed21 on 8.x-1.x authored by super_romeo
    Issue #3084387 by Megha_kundar, super_romeo, ultrabob, EmiliaC, Steven...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.