Setting value of relationship form field via $set closure

Does anyone know if it's possible to update a relationship field via the $set closure? Specifically, I've a form field representing an underlying belongsToMany relationship, which I need to be able to modify based on data that's fetched in the afterStateUpdated method of another field within the form. I've tried passing both the model instance itself and the instance's ID, but neither seems to work, so I'm wondering if there's some other approach I need to take.
4 Replies
toeknee
toeknee8mo ago
Yes it is, you need to pass in an array of data Please provide the code.
John Parker
John Parker8mo ago
Ahh… yep. Providing an array of relationship "destination" model IDs works perfectly. Many thanks for the nudge in the right direction, @toeknee 🙌 Worthy of note if the fact that the process doesn't work if the field you're targeting with $set is hidden - the relationship isn't updated. @toeknee In terms of my previous comment, should I create an issue on GitHub? I could understand the value not updating if the relationship field was set as disabled, but just being hidden doesn't feel like it should break the update.
toeknee
toeknee8mo ago
Of course, hidden are hidden and not touched 100% that's how LW works There is a new option for what you want I think, let me check Hmm I don't thinkso actually. this is hiddenOn
John Parker
John Parker8mo ago
Yeah, using hiddenOn or visibleOn work in the same manner as just setting the field as hidden - the relationship isn't updated.