processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

requiredIf is broken when using OR field1|field2=1 in complex condition #1942

Open hiboudev opened 2 weeks ago

hiboudev commented 2 weeks ago

Short description of the issue

A field 'cars' has this condition in requiredIf (via admin panel): teamEvent|mandatoryCarChoice=1,allowCarChoicePerRound=0,carClasses=''

teamEvent, mandatoryCarChoice and allowCarChoicePerRound: checkboxes carClasses: multiple page selector (completion)

The red star indicating that the field is required is working fine, but the validation when page is saved it not working in some cases, I don't see error message when I should. If I activate teamEvent it's OK, but if I activate mandatoryCarChoice it is not working.

Then, on a field 'carClasses' on the same page I set this condition: teamEvent|mandatoryCarChoice=1,allowCarChoicePerRound=0,cars=''

And now nothing is working at all for the validation when page is saved.

If I remove the OR |, letting only teamEvent or mandatoryCarChoice, it's working, so it seems the OR is well managed to display the red star but not for validating the page.

Expected behavior

When saving the page, if the requiredIf condition is not validated I should see an error message on the empty field (cars or carClasses).

Setup/Environment

ryancramerdesign commented 2 weeks ago

@hiboudev Are these regular fields on the page, or are they embedded within another type of field?

Are the checkboxes fields multiple checkbox fields, or just single checkbox fields? If multiple, you may want the "count" property instead, i.e. field.count>0, field.count=0, etc.

Try turning off server-side Inputfield dependency validation temporarily just to confirm that it's a server-side dependency issue, and not something else:

// in /site/config.php: 
$config->InputfieldWrapper = [ 'useDependencies' => false ];

If everything seems to work after doing that, remove that line from config.php, and now try editing the /wire/modules/Inputfield/InputfieldForm.module file and change the debug constant at the top to true:

const debug = true; // set to true to enable debug mode for field dependencies

Then edit your page and attempt to reproduce the condition. Save. It should give you a bunch of messages indicating what it validated. We may be able to identify where it's going wrong from these debug messages.

hiboudev commented 2 weeks ago

@ryancramerdesign

Are these regular fields on the page, or are they embedded within another type of field?

Yes, regular. I use fieldset and fieldset in tab, but I think it's not a problem?

Are the checkboxes fields multiple checkbox fields, or just single checkbox fields?

Single.

Try turning off server-side Inputfield dependency validation temporarily just to confirm that it's a server-side dependency issue.

The 2 fields are now always required, whatever the check-boxes statuses, is it expected?

We may be able to identify where it's going wrong from these debug messages.

Here are the messages with:

Note that there's also a showIf dependency on mandatoryCarChoice: "teamEvent=0", not sure if it's relevant.

image

And here are the messages by checking teamEvent (=1) instead of mandatoryCarChoice (=0), now the page is showing an error at save (missing carClasses, missing cars):

image