2013-11-04 49 views
1

呈現不要任何人對此有任何想法時,失蹤我已經呈現爲在view.Following右側的一列模板_contact.gsp是其代碼:<g:form> Grails中在Firefox

<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:form id="form-org" action="search">// this tag is not rendered 


      <input type="text" id="Company" value="search for..." name="Company" class="field">   

</g:form>   

</g:applyLayout><div> 

<label style="visibility:hidden" for="PRIVATE" class="lb">-------------------------------------</label><a onclick="$('#form-org').submit()" style="display:inline"><img src="/jbilling/images/icon-search.gif"></a></div> 

<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> 

當我在firefox中運行此代碼時,視圖呈現正常,但表單標記丟失。我在Firebug中檢查了此按鈕時單擊返回沒有響應。螢火蟲顯示源如下: 呈現的視圖源firefox對應於包含表單標記的applyLayout標記

<div class="row"> //notice this;form is absent 
<label for="contact-20.organizationName">Organization Name</label> 
<div class="inp-bg "> 

      <input type="text" class="field" name="Company" value="search for..." id="Company">   

</div> 

因爲從形式標籤div標籤這個轉換的,我的按鈕不起作用。 Plz幫助防止這種轉換...

回答

2

那麼,一個g:form不是由Firefox呈現,而是由服務器中的Grails呈現,它將向瀏覽器發送HTML form。但是你應該知道瀏覽器忽略嵌套表單,我猜這就是這種情況。

Grails大概呈現標記,瀏覽器忽略它,因爲它在另一個表單內。

您可以通過右鍵單擊頁面並選擇View Page Source來檢查是否屬於查看源代碼的情況 - 這將顯示Grails的確切輸出。

+0

感謝這個有價值的信息... :)你是正確的時候看頁面源我可以看到窗體標籤...然後你能告訴我是否有一種方法來呈現嵌套窗體...? – PassionateProgrammer

+1

不幸的是,HTML不允許使用嵌套窗體,因爲它是[此處顯示](http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/)(Ctrl-F「嵌套窗體」)。我認爲你的選擇是:1)製作幾個小表單,每個表單都有自己的動作和變量2)使用一個只有一個動作的大表單和幾個命名的提交按鈕,並在動作中放置一些邏輯來決定根據已使用的提交按鈕的名稱。 – elias

+0

就你而言,我想我會用幾種不同的動作形式,因爲你似乎想要真正不同的東西,並且它可以很好地分離。此外,由於您似乎在使用佈局渲染表單字段,因此您可能需要查看[Grails Fields插件](http://grails.org/plugin/fields)。 – elias