-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from ccancellieri/284-multiple_text
#284 Now the add buttow will point to the right component even if we have …
- Loading branch information
Showing
2 changed files
with
27 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
var scheming_multiple_text_init_done = false; | ||
this.ckan.module('scheming-multiple-text', function($, _) { | ||
return { | ||
initialize: function() { | ||
var container = this; | ||
var $this = $(this.el); | ||
var $template = $this.children('div[name="multiple-template"]'); | ||
var template = $template.html(); | ||
$template.remove(); | ||
MultipleText = { | ||
|
||
multiple_add: function(field_name){ | ||
var fieldset = $('fieldset[name='+field_name+']'); | ||
let list = fieldset.find('ol') | ||
let items = list.find('li') | ||
var copy = items.last().clone(); | ||
let input = copy.find('input'); | ||
input.val(''); | ||
list.append(copy); | ||
input.focus(); | ||
}, | ||
initialize: function() { | ||
if (!scheming_multiple_text_init_done) { | ||
$(document).on('click', 'a[name="multiple-add"]', function(e) { | ||
var $copy = $(template); | ||
$(this).closest('.scheming-fieldset').find('.multiple-text-group').append($copy); | ||
$copy.hide().show(100); | ||
$copy.find('input').focus(); | ||
e.preventDefault(); | ||
}); | ||
|
||
$(document).on('click', 'a[name="multiple-remove"]', function(e) { | ||
var $curr = $(this).closest('.multiple-text-field'); | ||
$curr.hide(100, function() { | ||
$curr.remove(); | ||
}); | ||
e.preventDefault(); | ||
var list = $(this).closest('ol').find('li'); | ||
if (list.length != 1){ | ||
var $curr = $(this).closest('.multiple-text-field'); | ||
$curr.hide(100, function() { | ||
$curr.remove(); | ||
}); | ||
e.preventDefault(); | ||
} | ||
else{ | ||
list.first().find('input').val(''); | ||
} | ||
}); | ||
scheming_multiple_text_init_done = true; | ||
} | ||
} | ||
}; | ||
return MultipleText; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters