尝试使用textarea phoenix表单助手时出错

时间:2016-04-06 14:35:37

标签: forms elixir phoenix-framework

我想在phoenix框架中为我的表单添加一个textarea。

<%= text_input f, :name, [class: "form-control", placeholder: "Votre nom *", required: ""] %>

完美无缺,但写作:

<%= textarea f, :message, [class="form-control", placeholder: "Votre message *", required: nil] %>

给我错误:

no function clause matching in Phoenix.HTML.Tag.build_attrs/3

这是完整的代码:

<!-- Contact Section -->
<section id="contact">
  <div class="container">
    <div class="row">
      <div class="col-lg-12 text-center">
        <h2 class="section-heading">Contactez-nous !</h2>
        <h3 class="section-subheading text-muted"></h3>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-12">
        <%= form_for @conn, search_path(@conn, :new), [name: :send_message], fn f -> %>
<%# <form name="sentMessage" id="contactForm" novalidate> %>
          <div class="row">
            <div class="col-md-6">
              <div class="form-group">
                <%= text_input f, :name, [class: "form-control", placeholder: "Votre nom *", required: "", 'data-validation-required-message': "Merci de bien vouloir rentrer votre nom"]  %>
                <%#<input type="text" class="form-control" placeholder="Votre nom *" id="name" required data-validation-required-message="Merci de bien vouloir rentrer votre nom">%>
                <p class="help-block text-danger"></p>
              </div>
              <div class="form-group">
                <%= email_input f, :email, [class: "form-control", placeholder: "Votre e-mail *", required: "", 'data-validation-required-message': "Merci de bien vouloir rentrer votre email"] %>
                <p class="help-block text-danger"></p>
              </div>
              <div class="form-group">
                <%= telephone_input f, :phone, [class: "form-control", placeholder: "Votre téléphone *", required: "", 'data-validation-required-message': "Merci de bien vouloir rentrer votre numéro de téléphone"] %>

                <%# <input type="tel" class="form-control" placeholder="Votre téléphone *" id="phone" required data-validation-required-message="Please enter your phone number."> %>
                <p class="help-block text-danger"></p>
              </div>
            </div>
            <div class="col-md-6">
              <div class="form-group">
                <%= textarea f, :message, [class="form-control", placeholder: "Votre message *", required: nil] %>
                <%#<textarea class="form-control" placeholder="Votre message *" id="message" required data-validation-required-message="Veuillez écrire un message"></textarea>%>
                <p class="help-block text-danger"></p>
              </div>
            </div>
            <div class="clearfix"></div>
            <div class="col-lg-12 text-center">
              <div id="success"></div>
              <button type="submit" class="btn btn-xl">Send Message</button>
              <%= submit "Search" %>
            </div>
          </div>
          <%# </form> %>
          <% end %>
      </div>
    </div>
  </div>
</section>

任何想法?

1 个答案:

答案 0 :(得分:3)

class之后你有一个拼写错误:

<%= textarea f, :message, [class="form-control", placeholder: "Votre message *", required: nil] %>

应该是

<%= textarea f, :message, [class: "form-control", placeholder: "Votre message *", required: nil] %>

您的代码编译正常,但相当于

<%= textarea f, :message, ["form-control", placeholder: "Votre message *", required: nil] %>

作为赋值运算符返回指定的值,并将其绑定到抛出错误的变量,因为函数需要一个名称值对列表。