Phoenix Html Form value not displaying if type is string

Hi,

I got .html.eex file showing my form. In one of my text inputs, I would like to see the value so I did it as such <%= text_input f, :for, value: @user_name, class: "form-control " %>

the value is there if I inspect my html on the browser for this case showing my name “Muhammad” but its not showing on the actual input field, but if I change the value to ID as in to show the user ID i.e value: @user_id it works and displays the ID as 1.

could the data type of the value be the reason. How can I solve this

Thanks

If it shows in the source but not the browser then is there some javascript or an extension clearing it or so?

there is no javascript. But if that’s the case it would also not show the id as well?

Depends, it could be trying to validate it somehow and wiping it if not. Do you have it hosted (temporarily?) somewhere so we can look at the generated page?

unfortunately no. for now its just on my local machine

Hi,
the :for, looks suspicious to me ?

Hmm, any chance of an SSCCE or so? Strip out everything in a branch of your program until the problem is shown with a minimal amount of code then post that so we can git clone it? :slight_smile:

Shouldn’t matter, it will go into the id and name fields, not as a for="..." thing.

okay I will do that and get back to you.

1 Like

Looking again at that line of code :slight_smile:
I think the following is more ‘usual’

<%= text_input f, :user_name, class: "form-control" %>

Only if :user_name exists in the form data, which isn’t always necessarily the case.

inspect type of form, if it is text.

<%= text_input f, :for, value: @user_name, type: :text,  class: "form-control" %>

Maybe your data type is wrong try this basic string

<%= text_input f, :for, value: "test",  class: "form-control" %>

yeah it is a text.

it works with a basuc string, but the idea it to have it dynamic/pick the value as the name of the person whose ID has been picked from the session. I hope you understand what I mean

Yes i understand what you mean.So input works as usual. The problem is @user_name

yes exactly

<%= text_input f, :for, value: "#{@user_name}", class: "form-control" %>

try that if it works

I have also tried doing this, it’s still not working

Something is strange. Click “Edit as html” in HTML tree and copy paste form source code here.

where do I click “Edit as html”

Inspect in browser. Right click HTML source code

ooooh I understand you now, my bad