how do you add a suffix to input, something like this:
<%= text_input f, hidden_value_suffix=“url:” %>
how do you add a suffix to input, something like this:
<%= text_input f, hidden_value_suffix=“url:” %>
Looking fast online, you can do this with CSS. The text_input
is just a helper and should accept anything an HTML input can accept.
This can also be accomplished with just html as well. but you would need to play with padding/margins/position/borders
thanks but I want to add a suffix to the input value that is sent on form submission
In this case you can setup a change_event like so:
<%= text_input f, phx_change: "url_changed", phx-value-suffix="url:" %>
Can look at binding docs for phx_change
And you can also look at Form Event docs example, look for email_changed
. From there you can have some logic to prepend the suffix if it is not there.
this works for live view, though you may want to do it with phx-submit
on the form so you are not mutating user input as they are typing, but only once on form submission
you could also make a case to put this at a different layer other than the interface, such as a context function if it’s a business rule. that would also make it agnostic to whether it’s a live view or regular view