Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

Multiple forms one submit.

Rails • Asked by kriera

Hi there!

I've a view that needs to generate a form table, based on clients and days. For 7 days it creates

View (i've tried to do
<%= form_for @effort, data: {remote: true} do |f| %>
<% @cli_list_id.map().uniq.each do |client| %>


<%= client.name %>
    <%  @days.each do |day| %>

    <th style="" colspan="2">
    <%= render 'home/dashboard/form', :user => current_user, :client => client, :day => day  %>
    <% end %>
    </th>
<% end %>
</tr>

<% end %>

<%= button_tag "Save", id: "button-feedback-by-bullet", data: {controller: "effort", target: "effort", action: "effort#getdate" } %>

with Flatpickr i do select the date i need and with this JS I do modify the ID and the classname of HTML elements to be able to generate individual input fields

generateDates (a){

console.log("data generateDates: " + a)
this.numArray = new Array(7);

for (var i = 0; i < this.numArray.length; i++) {
  var dateParsed = Date.parse(a).add(-[i]).day()
  var dateToload = Date.parse(dateParsed).toString('dd/MM/yyyy')
  this.header = new Array()
  var header = document.getElementsByClassName('dateTodayEffort-'+[i])
  document.getElementById('dateToday-'+[i]).innerHTML = dateToload

var ar_header = header.length;

for (var n = 0; n < ar_header; n++) {
header[n].value = dateToload

}

let forms = document.getElementsByTagName('form');
for (let index = 0; index < forms.length; ++index) {
var formId = 'form'+[index]
forms[index].id = formId

}

}

}

Controller:

def create
@effort = Effort.new(effort_params)

  if @effort.effort_time = nil

  else

 respond_to do |format|
  if @effort.save
    format.html { redirect_to dashboard_path , notice: 'Effort was successfully created.' }
    # format.json { render :show, status: :created, location: @effort }
  else
    format.html { render dashboard
     }
    format.json { render json: @effort.errors, status: :unprocessable_entity }
  end
end
      end
end

The problem i've is: once i do submit, it creates each input and do the redirect of each form

I would need to do some kinf of array of form data imput and once its saved then redirect or refresh page or whatever

any idea?

thanks in advance!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.