I am new to RoR/Padrino. I want to add an autofil functionality to a form. Lets say when a User ID is entered The Name of the User is shown in the name field. And when a specific user type is selected a dropdown menu only shows entries matching the user type.
What kind of technology do I need to use? I read a lot about jQuery and AJAX but I really feel lost in the huge amount of questions relating this "problem". Can someone give me a hint where and what to read in order to get the needed knowledge?
Thanks in advance Patrick
Here is an example:
$('#your_model_user_id').on('change', function() {
$.ajax({url: "/your_model/getname/" + $(this).val(),type: 'get'});
});
Then create an action in your_model:
def getname
@yourmodel = YourModel.find(params[:id])
end
Create a route:
get '/your_model/getname/:id' => 'your_models#getname'
create the file app/views/your_models/getname.js.erb:
$('#your_model_username').val('<%= @yourmodel.name %>');
In a nutshell
There are a few way to do that kind of stuff.
Here a few links which might help:
http://railscasts.com/episodes/88-dynamic-select-menus
http://blog.sandeep.me/2011/08/dynamic-select-menus-in-rails-3.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.