簡體   English   中英

Joomla! 組件表單和jQuery動態添加/刪除字段子集

[英]Joomla! component form and jQuery to add/remove subset of fields dynamically

我有一個用於管理研討會的Joomla組件,稱為com_workshops及其相應的表jos_workshops。

然后,我有了核心的com_users組件及其jos_users表。

我有一個鏈接表jos_works_users以便將用戶與工作坊(N,N)關聯。

我知道如何添加一個表單字段type =“ user”,以便可以從用戶模式視圖中選擇一個用戶。

但是我希望表單能夠像我一樣添加盡可能多的表單字段類型

並動態刪除它們。 我在想

jQuery (append(), clone(), remove() functions)

但不知道Joomla內是否可能! 表格,以及操作方法。

盡管使用了mootools,但我也做了類似的工作。 如果您是我,我將創建一個新的字段類型( Joomla docs ),然后使用JHTML :: script()將一些JavaScript添加到頁面中。 您需要使用輸入名稱(例如jform [userids] []),以便瀏覽器可以傳遞用戶ID數組。

我的案子與您的案子並不完全一樣,但這幾乎就是我做的事:

我的HTML如下所示(請注意,每行有兩個文本字段):

<div id="ingredientList1">
    <div class="ingredient-row">
        <div class="delete"></div>
        <input type="text" class="amountField" style="display: block; " name="jform[ingredientAmounts][]">
        <input type="text" class="nameField" style="display: block; " name="jform[ingredients][]">
    </div>
    <div class="ingredient-row">
        <div class="delete"></div>
        <input type="text" class="amountField" style="display: block; " name="jform[ingredientAmounts][]">
        <input type="text" class="nameField" style="display: block; " name="jform[ingredients][]">
    </div>
    <div class="ingredient-row">
        <div class="add"></div>
        <input type="text" class="amountField" style="display: none; ">
        <input type="text" class="nameField" style="display: none; ">
    </div>
</div>

您的JavaScript應該:

  1. 當用戶單擊刪除按鈕時,刪除一行(在mootools中:row.dispose())。
  2. 單擊添加按鈕時,使最后一行可見並創建一個新的隱藏行。
  3. 有一種方法可以從數據庫加載以前的數據。
  4. 將代碼加載到表中(選擇用戶ID)並存儲(將它們保存到db)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM