Skip to content

Added support for textarea element #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.2.4 (2016/06/17)
-------------------
- Changed the options to allow 'select', 'text', and 'textarea' input, the fourth parameter becomes the number of rows if textarea, straight json for select options

v1.2.3 (2015/04/20)
-------------------
- Added 'bower.json' to use this package manager
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# jQuery-Tabledit v1.2.3
# jQuery-Tabledit v1.2.4
Inline editor for HTML tables compatible with Bootstrap.


Expand Down
54 changes: 35 additions & 19 deletions jquery.tabledit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,42 @@ if (typeof jQuery === 'undefined') {

// Create span element.
var span = '<span class="tabledit-span">' + text + '</span>';

var input = "";
// Check if exists the third parameter of editable array.
if (typeof settings.columns.editable[i][2] !== 'undefined') {
// Create select element.
var input = '<select class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none;" disabled>';

// Create options for select element.
$.each(jQuery.parseJSON(settings.columns.editable[i][2]), function(index, value) {
if (text === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
});

// Create last piece of select element.
input += '</select>';
} else {
// Create text input element.
var input = '<input class="tabledit-input ' + settings.inputClass + '" type="text" name="' + settings.columns.editable[i][1] + '" value="' + $(this).text() + '" style="display: none;" disabled>';
// switch the third parameter to test for input type default is text
switch(settings.columns.editable[i][2])
{
case "textarea":
input = '<textarea ';
//each item in 4th object becomes attributes in select
$.each(settings.columns.editable[i][3], function(index, value) {
input += index + '="' + value + '" ';
});
input += 'class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none;" disabled>' + $(this).text() + '</textarea>';

break;
case "select":
// Create select element.
input = '<select class="tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none;" disabled>';

// Create options for select element.
$.each(settings.columns.editable[i][3], function(index, value) {
if (text === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
});

// Create last piece of select element.
input += '</select>';

break;

default:
// Create text input element.
input = '<input class="tabledit-input ' + settings.inputClass + '" type="text" name="' + settings.columns.editable[i][1] + '" value="' + $(this).text() + '" style="display: none;" disabled>';
break;
}

// Add elements and class "view" to table cell.
Expand Down