在项目表单中,用户可以克隆任何特定任务——这工作正常。我现在需要用新的时间戳替换复制的任务的索引 ID(它是一个时间戳)。我当前的代码只替换了一个 div。
如何用时间戳替换所有表单输入/标签字段 ID?我目前做一个 find() 然后替换。
任何想法都非常感谢!
$(function() {
$('form').on('click', '.clone-task', function(event) {
event.preventDefault();
var time = new Date().getTime();
var taskCopy = $(this).parents(".dupForm").clone();
$("#dupTask").append(workoutCopy);
var attributes = taskCopy.find('input').attr('name').replace(/\[\d+]/g, time);
alert(attributes);
});
});
任务表(ruby-on-rails):
<fieldset>
<div class="field">
<b><%= f.label :name, "Major Task" %></b> |
<%= f.text_field :name, :placeholder => "task name" %>
<%= f.hidden_field :_destroy %>
<%= link_to "remove", '#', class: "remove_fields" %>
</div>
<div class="field">
<%= f.label :time_start, "Scheduled Time" %><br />
<%= f.time_select :time_start, {:ampm => true, :minute_step => 15} %>
</div>
<div class="field">
<%= f.label :task_duration, "Task Duration(mins)" %>
<%= f.number_field :task_duration, size: 3 %>
</div>
<b>Add Supporting Actions to Your Task</b>
<%= f.fields_for :activities do |builder| -%>
<%= render 'activity_fields', f: builder %>
<% end %>
</div>
<%= link_to_add_fields "Add Action", f, :activities %>
</fieldset>