0

I'm working on a rails form which contain two text-fields. Each text-fields are fed values through a look-up button which popups modal windows, which will trigger an Ajax call to fetch values. Then I select the values and set the values to the text-box fields.

The problem I'm facing is, when I set value in the second text-field, the page gets refreshed and first value in the text-box gets updated.

In my controller for form I'm capturing the param values from each modal and passing to the template. But when setting the second textfield value parent page gets refreshed and so the previous value get lost.

My question is, how to set two values before the form is submitted.

<td><%= f.text_field_tag(:node, :id, value: "#{@node_id}", class: "form-control", :readonly => true )%></td>

enter image description here

Ashraf.Shk786
  • 618
  • 1
  • 11
  • 23
  • you can use local storage. – Neeraj Pathak Jul 30 '17 at 06:59
  • @pradeek why are you reloading the whole page? – Ashraf.Shk786 Jul 30 '17 at 07:02
  • @Ashraf.Shk786 When I select the value from the first modal then get back to the parent page the url get redirected right? –  Jul 30 '17 at 07:04
  • @pradeek no this shouldn't be the case. When you select anything from the modal the modal should get `refresh` everytime when you are trying to select/change value AND not the page. – Ashraf.Shk786 Jul 30 '17 at 07:10
  • @Ashraf.Shk786 Thanks, Here is my flow i click a lookup button the modal pops up and select the value then i pass values along with url redirection to the form page. After that the params values are captured by the form controller and set to input field in the form template. –  Jul 30 '17 at 07:16
  • 1
    Guys Thanks for the help , After a couple of thinking I come up with a simple solution to this, update me if I'm wrong. I chose to write a javascript event function to get the url and params values and append to the textbox and just close the modal window and not doing url redirection. –  Jul 30 '17 at 08:46

1 Answers1

0

First, try to control parent page from getting reloaded. Since, if page gets reloaded definitely you will not be able to get the parameters entered by user in the previous state.

Else, you can also set URL with parameters when URL gets reloaded then take the parameters from the URL at the time of reloading to set the first text box. So, in that way both your text box values have values in the same state.

For your reference to append parameters to the URL: append to url and refresh page

Ashraf.Shk786
  • 618
  • 1
  • 11
  • 23