Repository navigation
Conversation
A locked or non-editable Inputfield renders its value rather than an input, so inputfields.js has nothing to read for a showIf or requiredIf condition on it, and the dependent field is hidden (or its requiredIf never applies) whatever the locked field's value. Processing evaluates these conditions correctly, so the form shows one thing and processes another. A locked field's value can't change in the browser, so a condition on it has a fixed result when the form is rendered. InputfieldForm::resolveLockedDependencies() evaluates it with selectorMatchesInputfield(), the same code processInput() uses, and InputfieldWrapper::render() renders what is left: - a condition on locked fields that matches is removed from data-show-if or data-required-if - a showIf that can't match renders the field already hidden, as inputfields.js hides it (still in the page, so fields that depend on it can read it) - a requiredIf that can't match renders the field as not required - a condition naming locked and editable fields (a|b=1) keeps only the editable ones, unless a locked one matches No value is copied into the page, only whether a field is shown, and multi-value fields, .count, and option labels behave as they do in processing. OR-groups, fields outside the form, and locked fields with a showIf of their own are left unchanged. The Inputfields' own settings are not modified, so processing evaluates the original conditions. InputfieldForm::render() records itself as the form being rendered, since preRenderChildren() moves children into wrappers without a parent, so getForm() can't find it from the render loop. Fixes processwire/processwire-issues#1079
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs processwire/processwire-issues#1079
A locked or non-editable Inputfield renders its value rather than an input, so
inputfields.jshas nothing to read for ashowIf/requiredIfcondition on it: the dependent field stays hidden (or itsrequiredIfnever applies) whatever the locked field's value, whileprocessInput()evaluates the same condition correctly.This takes a different approach from the hidden-value workarounds in the issue, to address the concerns raised there: no value is rendered into the page. Since a locked field's value can't change in the browser, a condition on it has a fixed result when the form renders, so it is evaluated there and only what's left goes to the browser.
InputfieldForm::resolveLockedDependencies($selectorString)evaluates the conditions on locked fields withselectorMatchesInputfield(), the codeprocessInput()already uses, so.count, multi-value fields, and option labels behave exactly as they do in processing. It returns[$matches, $remainingSelector]:data-show-if/data-required-ifInputfieldStateHidden,display:none), the stateinputfields.jsleaves it in, so fields that depend on it can still read ita|b=1)InputfieldWrapper::render()applies this to local variables only, so the Inputfield'sshowIf,requiredIf, andrequiredsettings are untouched and processing evaluates the original conditions. The only thing the page reveals is whether a field shows, which it shows anyway."Locked" means rendered as a value: one of the locked
collapsedstates (the same listrender()uses), oreditable()false, which covers field-level access control (the case from the issue where a user can view but not edit the dependency field).InputfieldForm::render()records itself as the form being rendered (InputfieldWrapper::$renderForms), becausepreRenderChildren()moves children into wrappers that have no parent, sogetForm()returns null from the render loop.Testing
testLockedDependencies()inInputfieldForm.test.php(23 checks): matching, non-matching, and mixed conditions;a|bacross locked and editable fields; option labels; checkboxes with=,!=, and.count; a view-only (editable(false)) dependency; a field in a nested fieldset;requiredIftrue/false/mixed; OR-groups and locked fields with their own showIf left unchanged; settings unchanged after render; the locked value not copied into the markup. The existing InputfieldForm tests still pass.user_type(and a lockedsupport_needfor some users) with about a dozen fields depending on them, the rendered user edit forms match a site-level hook version of this, field for field.Not covered: Inputfields inside repeater items rendered in value mode, which Robin (Toutouwai) noted don't get
data-show-ifat all; this leaves them as they are.