I have created an input form for orders whereby I select an client as follows:
<div class="field">
<%= f.label :client_short, "Client Code Short" %><br />
<%= f.collection_select(:client_short, Client.order(:shortname), :shortname, :shortname)%>
</div>
Another column of the Clientis the column fullname. Now I want to retrieve and display in a non-editable textfield the value of the fullname based on the shortname for validation during the order entry.
I have no idea were to start so can somebody help me with an example please?
Use
javascriptfor this kind of task. I will make an example with purejQueryandjavascript, not usingcoffescript. Open up yourclient.js(formerclient.js.coffee, just rename it), and add anchangeevent to your list, displaying the full name on another field:Now you, have to create a action on your controller name
get_fullname, that respond tojavascript. Maybe something like this:Now you create a
get_fullname.js.erbfile on your/viewsfolder that displays the name on the uneditable field:Just check some minor typos and syntax errors and you are good to go.
Remember that this is just one way of many to do something like this.