Skip to content

Commit 95536dc

Browse files
committed
Fix #10
1 parent 6b0a934 commit 95536dc

File tree

9 files changed

+65
-17
lines changed

9 files changed

+65
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG: jquery.add-input-area
22

3+
## v4.10.0
4+
### New option
5+
`dont_clone` option is added to fix #8 .
6+
See [documentation](https://sutara79.github.io/jquery.add-input-area/#index_12).
7+
38
## v4.9.0
49
- All comments are written in English. ([isssue #4](https://github.com/sutara79/jquery.add-input-area/issues/4))
510
- Move plugin files to `dist/`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ https://sutara79.github.io/jquery.add-input-area/
1616
- [GitHub](https://github.com/sutara79/jquery.add-input-area): Clone or download.
1717
- [npm](https://www.npmjs.com/package/jquery.add-input-area): `npm i jquery.add-input-area`
1818
- CDN [(jsDelivr)](https://www.jsdelivr.com/):
19-
- [jquery.add-input-area.min.js (v4.10.0)](https://cdn.jsdelivr.net/npm/jquery.add-input-area@4.10.0/dist/jquery.add-input-area.min.js)
19+
- [jquery.add-input-area.min.js (v4.10.1)](https://cdn.jsdelivr.net/npm/jquery.add-input-area@4.10.1/dist/jquery.add-input-area.min.js)
2020

2121

2222
## Usage

dist/jquery.add-input-area.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery.add-input-area",
33
"description": "jQuery plugin to add or delete form fields.",
4-
"version": "4.10.0",
4+
"version": "4.10.1",
55
"license": "MIT",
66
"author": "Yuusaku Miyazaki <toumin.m7@gmail.com>",
77
"homepage": "https://github.com/sutara79/jquery.add-input-area",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @file jquery.add-input-area
3-
* @version 4.10.0
3+
* @version 4.10.1
44
* @author Yuusaku Miyazaki <toumin.m7@gmail.com>
55
* @license MIT
66
*/

src/methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default {
115115
ev.preventDefault();
116116

117117
// Delete the wrapper
118-
var idx = $(this.elem).find(this.option.btn_del).index(ev.target);
118+
var idx = $(this.elem).find(this.option.btn_del).index(ev.currentTarget);
119119
$(this.elem).find(this.option.area_var).eq(idx).remove();
120120

121121
// If the wrapper is single, del-button is not displayed.

test/unit/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<script src="jQuery.addInputArea/renumberFieldEach.js"></script>
3030
<script src="integration/test.js"></script>
3131
<script src="integration/dont_clone.js"></script>
32+
<script src="integration/current-target.js"></script>
3233

3334
<script>
3435
mocha.run(function (err) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file Integration Testing
3+
* @see https://github.com/sutara79/jquery.add-input-area/issues/10
4+
*/
5+
describe('event.currentTarget', function () {
6+
var target;
7+
beforeEach(async function () {
8+
target = $(`
9+
<ol id="list">
10+
<li class="list_var">
11+
<input type="text" size="30" name="list_0" id="list_0">
12+
<button type="button" class="list_del">
13+
<span class="del-child">Delete</span>
14+
</button>
15+
</li>
16+
</ol>
17+
<input type="button" value="Add" class="list_add">
18+
`).appendTo('body');
19+
await target.addInputArea();
20+
await $('#list_0').val('a');
21+
await $('.list_add').trigger('click');
22+
await $('#list_1').val('b');
23+
await $('.list_add').trigger('click');
24+
await $('#list_2').val('c');
25+
});
26+
27+
afterEach(function () {
28+
target.remove();
29+
});
30+
31+
it('should remove certain element when clicking button', async function () {
32+
await $('.list_var').eq(0).find('.list_del').trigger('click');
33+
assert.equal($('.list_var').length, 2);
34+
assert.equal($('#list_0').val(), 'b');
35+
});
36+
37+
it('should remove certain element when clicking span', async function () {
38+
await $('.list_var').eq(0).find('.del-child').trigger('click');
39+
assert.equal($('.list_var').length, 2);
40+
assert.equal($('#list_0').val(), 'b');
41+
});
42+
});

test/unit/integration/dont_clone.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ describe('Option: dont_clone', function () {
55
var target;
66
beforeEach(function () {
77
target = $(`
8-
<ol id="list">
9-
<li class="list_var">
10-
<div>This will be cloned.</div>
11-
<div class="dont_clone">This will NOT be cloned.</div>
12-
<input type="text" size="30" name="list_0" id="list_0">
13-
<button type="button" class="list_del">Delete</button>
14-
</li>
15-
</ol>
16-
<input type="button" value="Add" class="list_add">
8+
<ol id="list">
9+
<li class="list_var">
10+
<div>This will be cloned.</div>
11+
<div class="dont_clone">This will NOT be cloned.</div>
12+
<input type="text" size="30" name="list_0" id="list_0">
13+
<button type="button" class="list_del">Delete</button>
14+
</li>
15+
</ol>
16+
<input type="button" value="Add" class="list_add">
1717
`).appendTo('body');
1818
});
1919

@@ -24,12 +24,12 @@ describe('Option: dont_clone', function () {
2424
it('should clone', async function () {
2525
await target.addInputArea(); // The dont_clone option is not set.
2626
await $('.list_add').trigger('click');
27-
await assert.equal($('.list_var').eq(1).find('.dont_clone').length, 1);
27+
assert.equal($('.list_var').eq(1).find('.dont_clone').length, 1);
2828
});
2929

3030
it('should not clone', async function () {
3131
await target.addInputArea({dont_clone: '.dont_clone'});
3232
await $('.list_add').trigger('click');
33-
await assert.equal($('.list_var').eq(1).find('.dont_clone').length, 0);
33+
assert.equal($('.list_var').eq(1).find('.dont_clone').length, 0);
3434
});
3535
});

0 commit comments

Comments
 (0)