How to use fillForm() with a repeater?
Hey, I'm trying to set up some tests for my application but how do I use fillForm with a repeater?
This doesn't seem to work.
This doesn't seem to work.
16 Replies
is
products
your repeater?
repeaters are an array of arraysYea, products is my repeater
Nope, that's an array of properties.
Would you be able to give me an example of what it should look like?
Wrap an extra set of [] around it. Although it may need a string key, iirc. Lemme check something, brb.
Ok thanks
So might need to be sometrhing like ...
Thanks, I'm still getting an error but it's no longer about the products repater lol.
Appreciate the help!
Well, that's progress, at least.
Is it a relationship repeater? I'm not sure what they use as temporary keys when adding, whether it's a random uuid or some special key.
Nah, it's just a basic json field repeater
The error I'm getting now says Illegal offset type
Try it without the key. Looking at my code, it was a relationship repeater I'm using uuid's with. Maybe JSON repeaters don't use string keys.
Without the key I'm back to getting the previous error which is
The above error is if I'm using
Not sure. I'm writing a test suite atm, and at some point maybe this evening I'll get as far as one of my forms with a repeater. If so I'll check back in here when I figure it out. The code I was looking at which fills a relationship repeater is on an actual form, not using fillForm in a test.
Okay, appreciate the help, thanks
Sorry I couldn't be of more help.
No worries
So I figured out what's causing the problem but I don't know how to get around it. By default the repeater input type has a single empty item. When I use the form fill method, it's adding to that repeater array instead of replacing it completely. However, because those form fields are required, it's throwing an form error for the empty fields that are initially there.
If for example I set "->defaultItems(0)" on the repeater, then it solves my testing woes. However, I'd prefer that the UI actually does show an initial empty field, so I'd rather not have to do that.
Is there a way in the test maybe to either replace the existing empty fields in the repeater array altogether or at least get the UUID that's generated for them so I can assign values to those form fields?
Figured out how to do it....
Have to add ->set('data.products', [])