This can happen when there's a validation error. The field with error will also be marked changed, but the error style will override it.
I'd like to move this into a FormBuilder. Existing formbuilder gems don't seem to support it (though I didn't look very hard).
The feature toggle will determine which bulk products screen shows. An additional products_old path is also temporarily added for easy reference.
Later, when the old screen is full removed, we'll probably rename the _v3 classes to tidy up.
The form helper () doesn't work for this case, but it seems we can call it directly like this instead. I'd like to fix the helper, but got stuck this time.
Stimulus controllers aren't supposed to reach outside their own element (so we can't do this with targets). Perhaps the controller should be bigger to encompass more, but I wanted to see if I could avoid making a mega component that does everything. For now it seems appropriate just to pass a selector in.
Another option is to publish events on other controllers using Outlets, but I don't know if we need to go there just yet.
I found myself trying to write Ruby in Javascript, and it's not nearly as pretty..
Javascript now has more advanced data structures like Map, but it's rather useless because it doesn't have the usual iterator methods (such as filter, map, reduce etc).
Also for the spec I wasn't sure of the best approach, so will gladly recieve feedback.
Now we don't have to specify the field names on products, yay!
I tried desparately to get it working for the nested variant forms too, but sadly the form builder refuses to acknowledge the relationship. The form builder simply doesn't support a collection of objects in this way.
We could try creating a fake model similar to ProductSet that accepts_nested_attributes_for :products. But it woudl be better to create a custom form builder to do it.
Or, just manually specify field names for now!
I have to admit I don't fully understand why, but it seems to work, even though the rails guide says "only one level of arrayness is allowed (https://guides.rubyonrails.org/form_helpers.html#combining-them). Maybe it's ok here because it's not an array of arrays.
(I think this format is what the reflex spec was already testing).