0
votes

Is it possible using Rails 4 and simple_form to start creating a new object, finish typing the first field in the form (let's assume autocompletion is set up and the user picks a pre-existing option), and then hits enter -> now based on that I want the rest of the form to autocomplete since the info is already in the database... i.e. I don't want to have multiple users filling out the whole form for the same thing over and over.

Is there a way to autocomplete an entire FORM (not just a single field) based on the results entered in one field? We can assume that when the user focuses out of the field in question, the other fields perhaps perform an AJAX call to retrieve the rest of the info...

1
Instead of creating something new, you are linking to something exisiting? Or could you please describe in a little more detail what you are trying to do. Yes this is possible. No, it is not default or standard. You will be creating a lot of copies if you do it like this, and I am wondering if that is what you want?nathanvda
You are correct, this would entail building a database with huge redundancy, however I also anticipate Users will be destroying many records as they go... hopefully offsetting the issue. The bigger problem I have is what to do when you have many Items in your database that are not overtly shared between Users, but that are identical? I'm not sure how to handle this scenario apart from giving everyone their own compartmentalised copies of Items.John Trichereau

1 Answers

1
votes

In your form you can link to a new action, for instance autocomplete such that:

def autocomplete
  @autocompleted_user = User.find_by_some_value(some_params)
  ...other relevant code
  format.html {render action: 'new'}
end

and in your form, you can add this to the fields you want to autocomplete such as:

value: @autocompleted_user ? @autocompleted_user.some_attribute : ''

I personally do not think it is a good idea if the form will provide sensitive information, since all the attacker would need to get all the user's information is that one initial value