Home

jquery.add-input-area

jQuery plugin for adding or deleting Form elements.

Demo

http://www.usamimi.info/~sutara/sample/add-input-area/

JSDoc

http://www.usamimi.info/~sutara/sample/add-input-area/jsdoc/

Usage

HTML
<head>
    <script src="//code.jquery.com/jquery.min.js"></script>
    <script src="jquery.add-input-area.min.js"></script>
</head>
<body>
    <ol id="list1">
        <li class="list1_var">
            <input type="text" size="40" name="list1_0" id="list1_0">
            <button class="list1_del">Delete</button>
        </li>
    </ol>
    <input type="button" value="Add" class="list1_add">
JavaScript
$('#list1').addInputArea();

Attention

You must set name attribute to addable elements.
But id attribute is not required.
(増減する要素にはname属性が必須です。
しかし、id属性は必須ではありません。)

If you obey a naming convention, name and id attribute is named automatically.
(命名規則に従えば、name, id属性には自動で連番が割り当てられます。)

(default)
<input type="text" name="foo_0">

(add)
<input type="text" name="foo_1">
<input type="text" name="foo_2">
<input type="text" name="foo_3">

On the other hand, you can set original method of numbering using name_format or id_format attribute.
(他方で、独自属性のname_formatid_formatを使うことにより柔軟な連番生成も可能です。CakePHPへの対応などで役立ちます。)

example 1.

(default)
<input type="text" name_format="foo_%d_bar" name="foo_0_bar">

(add)
<input type="text" name_format="foo_%d_bar" name="foo_1_bar">
<input type="text" name_format="foo_%d_bar" name="foo_2_bar">

example 2.

(default)
<input type="text" name_format="data[posts][mail][%d]" name="data[posts][mail][0]">

(add)
<input type="text" name_format="data[posts][mail][%d]" name="data[posts][mail][1]">
<input type="text" name_format="data[posts][mail][%d]" name="data[posts][mail][2]">

How to use on CakePHP

http://runnable.com/U7vCAlCwvQZzFZBO/

Author

Yuusaku Miyazaki (宮崎 雄策)

  • Mail: toumin.m7@gmail.com
  • Blog

License

MIT License

jquery.add-input-area.js

jQuery Plugin: jquery.add-input-area
Version:
  • 4.7.2
Author:
  • Yuusaku Miyazaki [toumin.m7@gmail.com]
License:
  • MIT License
Source:

jquery.add-input-area.min.js