Closed kumy closed 4 weeks ago
@kumy the UpdateOnlyTextField isn't used very often, but the easiest fix to make it work would be to add a public function to get the value in BaseField and refactor the constraints to use that method instead of the current one. We only have to come up with a sensible name and change the few callers where this is relevant. Maybe something like getCurrentValue
would be work?
Ok, looks like we have the same conclusion. Would you like a PR or you are on it?
getCurrentValue
looks fine.
@kumy if you're up for a PR, I'll just wait for it :)
FWIW: Since it was said the fieldtype is rare, I wanted to add an example where I use it:
I dont have anything more to add. Just thought it might be interesting.
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
Describe the bug
Using
DependConstraint
withUpdateOnlyTextField
fields always trigger the validation messageTo Reproduce In a custom plugin…
Given such xml (simplified) model, the
aws_secret_access_key
field validation always trigger an error.Expected behavior
Should not trigger an error when the user enter a value, and should not trigger error on further saves
Describe alternatives you considered
Switching the field type to
TextField
don't trigger intepestive error.Screenshots We can see that a value is really posted.
Relevant log files
N/A
Additional context
I think I get the problem… The
validate()
fromDependConstraint
class check the value by callingisEmpty()
(link). TheisEmpty()
fromBaseConstraint
checks if the value is empty usingempty((string)$node)
(link). Calling this on the$node
will call the__toString()
method from theFieldtype
which normally return the fieldinternalValue
(link)But the
UpdateOnlyTextField
overrides__toString()
for good reason ;) (link)…Initial idea was to replace
empty((string)$node)
check byempty((string)$node->internalValue)
, but$internalValue
is protected value fromBaseField
thus cannot be used.I didn't found any other
getter
for it, should one be created?Environment
Fresh install in VirtualBox
OPNsense 24.7.4_1-amd64 FreeBSD 14.1-RELEASE-p4 OpenSSL 3.0.15