I’m using simple_form for a form and passing in some URL parameters
to prepopulate the form.
This code works OK
<%= f.input :first_name, :label => 'First Name', :input_html => { :value => params['first'] } %>
Using the URL
http://localhost:3000/charities/new?first=Bob
Which outputs this HTML
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" value="Bob" />
However if the form server side validation fails the page reloads but the prepopulate
value is gone? This is the rendered HTML
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" />
Can anyone help advise how to prepopulate simple_form and retain those
values if the serverside validastion fails and the page reloads?
Thank you.
if you want to make it works with validations you should preset object values in controller like this: