0

请帮我解决这个问题。我需要在用户在文本字段中输入字母时搜索匹配的公司名称。在 grails 中,只有当我们提交周围的表单时,我们才能从文本字段中获取输入。但在我的情况下,我无法提交表单,因为在执行搜索时大多数字段将为空,并且不允许提交空字段。此外,我不能为此 textField 使用单独的表单,因为嵌套表单将被浏览器忽略。所以我现在该怎么办?以下是我的代码:

 <div id="contact-${contactType.id}" class="contact" style="${contactType.isPrimary == 1 ? '' : 'display: none;'}">

 <g:hiddenField name="contact-${contactType?.id}.id" value="${contact?.id}"/>


 <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.organization.name"/></content>
    <content tag="label.for">contact-${contactType?.id}.organizationName</content>
     <g:textField class="field" name="Company" value="search for..." />
     <g:submitButton  id="button" class="buttons" name="Search" value="Search" action="search" src="/jbilling/images/icon-search.gif" style= "background-color:#191DD4 text-color:#FFFFFF"/>//This is what i tried but not useful for my case...
</g:applyLayout>


  <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.first.name"/></content>
    <content tag="label.for">contact-${contactType?.id}.firstName</content>
    <g:textField class="field" name="contact-${contactType?.id}.firstName" value="${contact?.firstName}" />
</g:applyLayout>

 <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.last.name"/></content>
    <content tag="label.for">contact-${contactType?.id}.lastName</content>
    <g:textField class="field" name="contact-${contactType?.id}.lastName" value="${contact?.lastName}" />
 </g:applyLayout>

 <g:applyLayout name="form/text">
    <content tag="label"><g:message code="prompt.phone.number"/></content>
    <content tag="label.for">contact-${contactType?.id}.phoneCountryCode</content>
    <span>
        <g:textField class="field" name="contact-${contactType?.id}.phoneCountryCode" value="${contact?.phoneCountryCode}" maxlength="3" size="2"/>
        -
        <g:textField class="field" name="contact-${contactType?.id}.phoneAreaCode" value="${contact?.phoneAreaCode}" maxlength="5" size="3"/>
        -
        <g:textField class="field" name="contact-${contactType?.id}.phoneNumber" value="${contact?.phoneNumber}" maxlength="10" size="8"/>
    </span>
 </g:applyLayout>

 <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.email"/></content>
    <content tag="label.for">contact-${contactType?.id}.email</content>
    <g:textField class="field" name="contact-${contactType?.id}.email" value="${contact?.email}" />
 </g:applyLayout>

 <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.address1"/></content>
    <content tag="label.for">contact-${contactType?.id}.address1</content>
    <g:textField class="field" name="contact-${contactType?.id}.address1" value="${contact?.address1}" />
</g:applyLayout>

  <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.address2"/></content>
    <content tag="label.for">contact-${contactType?.id}.address2</content>
    <g:textField class="field" name="contact-${contactType?.id}.address2" value="${contact?.address2}" />
 </g:applyLayout>

  <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.city"/></content>
    <content tag="label.for">contact-${contactType?.id}.city</content>
    <g:textField class="field" name="contact-${contactType?.id}.city" value="${contact?.city}" />
  </g:applyLayout>

  <g:applyLayout name="form/input">
     <content tag="label"><g:message code="prompt.state"/></content>
    <content tag="label.for">contact-${contactType?.id}.stateProvince</content>
    <g:textField class="field" name="contact-${contactType?.id}.stateProvince" value="${contact?.stateProvince}" />
 </g:applyLayout>

 <g:applyLayout name="form/input">
    <content tag="label"><g:message code="prompt.zip"/></content>
    <content tag="label.for">contact-${contactType?.id}.postalCode</content>
    <g:textField class="field" name="contact-${contactType?.id}.postalCode" value="${contact?.postalCode}" />
 </g:applyLayout>

 <g:applyLayout name="form/select">
    <content tag="label"><g:message code="prompt.country"/></content>
    <content tag="label.for">contact-${contactType?.id}.countryCode</content>

    <g:select name="contact-${contactType?.id}.countryCode"
              from="${CountryDTO.list()}"
              optionKey="code"
              optionValue="${{ it.getDescription(session['language_id']) }}"
              noSelection="['': message(code: 'default.no.selection')]"
              value="${contact?.countryCode}"/>
 </g:applyLayout>

 <g:applyLayout name="form/checkbox">
    <content tag="label"><g:message code="prompt.include.in.notifications"/></content>
    <content tag="label.for">contact-${contactType?.id}.include</content>
    <g:checkBox class="cb checkbox" name="contact-${contactType?.id}.include" checked="${contact?.include}"/>
 </g:applyLayout>
 </div>
4

3 回答 3

1

看看优秀的select2 javascript 库。具体来说,请参阅“加载远程数据”部分。

于 2013-11-04T12:05:49.360 回答
0

好吧,看来您只需要一个自动完成功能...阅读此内容!

Grails 通过 jqueryui 和 AJAX 自动完成

于 2013-11-06T05:33:25.603 回答
0

我建议使用可搜索插件

http://grails.org/plugin/searchable 查看

于 2014-03-15T10:14:35.370 回答