-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore null values in subform rule #34585
Conversation
@laoneo do you have a default value for subform field? |
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. |
This comment has been minimized.
This comment has been minimized.
The test function needs to return true or false. |
okay, I not sure we have it in core, but such may be used in other extensions also 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 joomla-cms/libraries/src/Form/Rule/SubformRule.php Lines 86 to 88 in 368a1f3
And try save the module, |
Ok thanks, updated the testing instructions. |
I have tested this item ✅ successfully on 6a9ebdc This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34585. |
1 similar comment
I have tested this item ✅ successfully on 6a9ebdc This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34585. |
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34585. |
Thanks! |
Summary of Changes
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?Testing Instructions
Actual result BEFORE applying this Pull Request
The warning mentioned above is added to the logs of the server.
Expected result AFTER applying this Pull Request
No Warning.