User tests: Successful: Unsuccessful:
The subform rule can get null as value to validate. This throws the following warning:
Warning: foreach() argument must be of type array|object, null given in /var/www/html/j3/libraries/src/Form/Rule/SubFormRule.php on line 52
@Fedik can you help here with a test case in core?
<field type="subform" name="subform" multiple="true" label="subform"
validate="subform" filter="unset">
<form>
<field type="text" name="text" label="text" />
</form>
</field>
The warning mentioned above is added to the logs of the server.
No Warning.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
the error probably because of wrong JSON in default value :
joomla-cms/libraries/src/Form/Field/SubformField.php
Lines 445 to 456 in 9bd9e52
you can get this error with this field:
<field type="subform" name="subform" multiple="true" label="subform"
validate="subform" default="{'blabla', 'bad json'}">
<form>
<field type="text" name="text" label="text" />
</form>
</field>
No default value. The problem is that I do an filter="unset" before. So it is really NULL as value.
hmhm, maybe a good idea also modify
joomla-cms/libraries/src/Form/Field/SubformField.php
Lines 451 to 455 in 9bd9e52
to:
// The string is invalid json
if (!$value)
{
return $this->multiple ? [] : null;
}
The test function needs to return true or false.
The problem is that I do an filter="unset" before. So it is really NULL as value.
okay, I not sure we have it in core, but such may be used in other extensions also
then maybe this:
Place it in mod_custom:
<field type="subform" name="subform" multiple="true" label="subform"
validate="subform" filter="unset">
<form>
<field type="text" name="text" label="text" />
</form>
</field>
Add dump($value);exit;
before return here:
joomla-cms/libraries/src/Form/Rule/SubformRule.php
Lines 86 to 88 in 368a1f3
And try save the module,
Before : you will get warning, then dump result;
After: only dump result
Ok thanks, updated the testing instructions.
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-06-29 20:18:09 |
Closed_By | ⇒ | HLeithner | |
Labels |
Added:
?
?
|
Thanks!
@laoneo do you have a default value for subform field?