- Issue created by @brad.bulger
- ๐ฉ๐ชGermany Anybody Porta Westfalica
This is a further case of ๐ Fields with unlimited cardinality show 1 extra input field Needs work
- ๐ญ๐บHungary pasqualle ๐ญ๐บ Budapest
Same problem when the first item is moved/reordered. The item[0] is highlighted as required even it is not the first on the list.
- ๐ง๐ชBelgium bernardopaulino Brussels
I've implemented a temporary patch which avoids setting the 'required' property as true for the first element in a multi-value field. This is because the parent field already has the 'required' property set and drupal will perform the validation as expected. The current downside of this fix is a generic error message and a red border displaying around all elements, and not just the first one.
For a more robust solution, I propose we improve the
doValidateForm()
method in the\Drupal\Core\Form\FormValidator
class. This way, we can have a more specific and clear validation error message and possibly a cleaner way to handle the required attribute for multi-value fields. - Status changed to Needs work
7 months ago 4:29pm 18 June 2024 - ๐ฉ๐ชGermany FeyP
Did a little bit of testing using the workaround patch in #4 and for now it looks like it works as promised (i.e. the bug is fixed with the mentioned limitations).
Let's set the issue status to needs work, since there is now a patch and there is also a more concrete proposed resolution in #4.
- First commit to issue fork.
- Merge request !8454Issue #3344082: Improve required validation of multiple value fields โ (Open) created by Unnamed author
- Status changed to Needs review
7 months ago 3:46am 19 June 2024 - Status changed to Needs work
7 months ago 1:39pm 24 June 2024 - ๐ฉ๐ชGermany marc.bau
This patch has not helped me with muli-field validation.
I have a field that is limited to two values and *both* fields need to be filled, not just the first field. This does not work properly.
- ๐ฎ๐ณIndia anandhi karnan Chennai
anandhi karnan โ made their first commit to this issueโs fork.
- ๐ฎ๐ณIndia anandhi karnan Chennai
Hi
I have created tests to report the bug. Please review it.
Steps to reproduce
- Add a new field. Set it to multiple values and mark it as required.
- Create a Node and enter the values for the multi value field
- Value 1: foo
- Value 2: bar
- Value 3: baz
- Save the node
- Edit the node, empty the first value 'foo'
- Click Save to submit the edited node.
- You should see an error message indicating that the first text field is required.
Thanks!
- ๐ฌ๐งUnited Kingdom oily Greater London
@anandhi I have pulled the issue fork and run your test. I got this error:
"There was 1 failure:
1) Drupal\Tests\Core\Field\MultipleValueFieldTest::testRequiredMultiValueField
Failed asserting that 'j4flhnm5 | Drupal Skip to main content Status message Page j4flhnm5 has been updated. j4flhnm5 Member for 1 second Submitted by r6okpbnh on Tue, 24 Sep 2024 - 09:55' [ASCII](length: 164) contains "Test Text (value 1) field is required." [ASCII](length: 38)./var/www/html/core/tests/Drupal/Tests/Core/Field/MultipleValueFieldTest.php:80"
So your test may need work.
- ๐ฌ๐งUnited Kingdom oily Greater London
After applying patch #4 to the issue fork I have done the reproduce the issue steps in the UI (a Drupal 11.x site). After setting the field to 'Required' and deleting the 'foo' value leaving only the 'bar' value I saved the node without any error. I notice that the 'bar' value is repositioned to the topmost (first) textbox.
The test seems to need work. It would be useful to test a few scenarios like saving 'foo', 'bar' and 'baz' with the field set to 'Required'.
Then delete 'foo' and 'bar'. Does 'baz' get moved to the first, topmost checkbox?
Then delete 'foo' and 'baz' and so forth..
Also try some field setting variations like setting the 'Limit' of values to 4 or 5. And try saving 'foo' in the 2nd textbox, 'bar' in the 3rd and 'baz' in the 5th (last) textbox.
- ๐ฌ๐งUnited Kingdom oily Greater London
It seems that in addition to requiring work on the new test, other tests are broken by the fix, for example, an image file field test in the image core module. This may mean that testing with other field types may be necessary to avoid regression.