简体   繁体   English

如何在加载时显示表格

[英]How to show a form on load

How to show form on load. 如何显示负载形式。 Now I can see form fields on click of button (add keyskills). 现在,我可以在单击按钮(添加按键技能)时看到表单字段。 I want all function to be work together.On load i want to see the form and onclick 'add key skill' or 'remove key skill' it should add and remove(now on click of add or remove it is working, but not sees the form on load, only on click of 'add key skill' i can see the form) 我希望所有功能都可以一起工作。在加载时,我想查看表格并单击onclick``添加关键技能''或``删除关键技能'',它应该添加和删除(现在单击添加或删除它就可以了,但看不到加载表格,只有点击“添加关键技能”,我才能看到该表格)

$(function()
{
    function check_to_hide_or_show_add_key_skill_link()
    {
        if ($('#key_skills .nested-fields:visible').length == 4) {
            $('#key_skills .links a').hide();
        } else {
            $('#key_skills .links a').show();
        }
    }

    $('#key_skills').on('cocoon:after-insert', function()
    {
        check_to_hide_or_show_add_key_skill_link();
    });

    $('#key_skills').on('cocoon:after-remove', function()
    {
        check_to_hide_or_show_add_key_skill_link();
    });

    check_to_hide_or_show_add_key_skill_link();
});

My form Key Skills* 我的表格关键技能*

<div id="key_skills">
  <%= f.simple_fields_for :key_skills do |key_skill| %>
    <div class="nested-fields">
      <div class="field">
        <%= f.input :name , input_html: { class: 'form-control keySkill', required: true }%>
          <%= f.input :relevant_experience, input_html: { class: 'form-control', required: true } %>
            <%= link_to_remove_association "Remove Skill", f %>
      </div>
    </div>
    <% end %>
      <div class="links">
        <%= link_to_add_association 'Add Key Skill', f, :key_skills, class: "links" %>
      </div>
</div>

This is my current output now. 这是我当前的输出。 On click of add key skill i will get form,but i want it on load) 在单击添加关键技能时,我将获得表格,但我希望它在加载时) 在此处输入图片说明

Since you do not provide a lot of information, I have no idea what the name of the top-element is, but let us assume it is a Job and a job has many key_skills . 由于您没有提供很多信息,所以我不知道顶级元素的名称是什么,但是让我们假设它是Job并且Job具有很多key_skills

In your JobsController there is a create method, more or less as follows: 您的JobsController有一个create方法,大致如下:

def create
  @job = Job.new 
end 

if you want to immediately add a key-skill to fill in you can just write 如果您想立即添加一个关键技能来填写,您可以编写

def create
  @job = Job.new 
  @job.key_skills.build 
end 

(which will add an empty key-skill to fill in). (这将添加一个空的键技能以进行填写)。

Related issue on cocoon-repository: https://github.com/nathanvda/cocoon/issues/420 茧库的相关问题: https : //github.com/nathanvda/cocoon/issues/420

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM