MD - Is there a preferred method or package for...
# ❓questions
m
Is there a preferred method or package for handling URL fields? Like in a perfect world it'd be a JSON column with
{ url, title, target }
values and a single
@formField
i
Hi @MD to save multiple fields in a JSON column, check fields grouping: https://twillcms.com/docs/form-fields/field-grouping.html
regarding a single field to do that, we use a blade partial so we can just do @formField('link') in our forms. It is usually more complex than just 3 input fields though as we also use browser fields in link fields to let the user pick an internal page.
m
ah yeah forgot about the field grouping feature 🙂
I'm mainly after a generic url field, like if I made a package for it I'd wanna put browser-like autocomplete in it for internal URLs but still just a plain url
if it doesn't exist I'll just make one lol and submit a pull request
i
we try to avoid storing hardcoded urls in db for internal records at all cost
m
they should be pretty fixed though given modules route are hardcoded?
i
your frontend routes can change over time
m
cos it's either have a "url" field with dynamic urls (which is basically a browser) with no support for custom URLs, or a string url that has potential to go out of sync in the off chance you change your routes file
tbh I like both
so the Browser field, but still need a string url field
i
Yes we do both basically, so you can do external urls, browser based internal link, or custom internal urls
Using conditional fields
m
ah yeah
but like, a radio button for internal vs external then show a browser or text field conditionally?
i

https://cdn.discordapp.com/attachments/1101379328035528754/1101474120337723392/screenshot_2023-04-28_at_1.41.39_pm.jpg

https://cdn.discordapp.com/attachments/1101379328035528754/1101474120715223060/screenshot_2023-04-28_at_1.43.44_pm.jpg

Oh it's in french lol sorry
but you get the idea
Depending on use case we still keep a url field with the browser field, eg, to add a specific anchor, or link to a page they can't find in the browser