Skip to content

Commit

Permalink
readonly and disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-vercelli committed Jul 26, 2019
1 parent 30d3c4a commit d45e0b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ Following column options are supported.

| Column option | Accepted values | Description |
|------------------------|-----------------------------------------|-----------------------------------|
| `type` | `"text" \| "select" \| "hidden" \| "readonly"` | Type of HTML input to be shown. |
| `type` | `"text" \| "select" \| "hidden" \| ...` | Type of HTML input to be shown. The value `readonly` is accepted for backward compatibility, but deprecated. |
| `readonly` | `true \| false` | Add `readonly` HTML attribute |
| `disabled` | `true \| false` | Add `disabled` HTML attribute |
| `hoverMsg` | `"some msg"` | The message will appear as a tooltip over the input field. |
| `unique` | `true \| false` | Ensure that no two rows have the same value. The check is performed client side, not server side. Set HTML `"data-unique"` attribute. (Probably there's some issue with this). |
| `uniqueMsg` | `"some msg"` | An error message that is displayed when the unique constraint is not respected. Set HTML `"data-uniqueMsg"` attribute. |
| `special` | `"any string"` | Set HTML `"data-special"` attribute (don't know what's that needed for). |
| `special` | `"any string"` | Set HTML `"data-special"` attribute (don't know what's that needed for). |
| | |
| **Options for columns with type `"text"`:** | | |
| `pattern` | `r.e.` | The typed text will be matched against given regular expression, before submit. |
Expand Down
45 changes: 22 additions & 23 deletions src/dataTables.altEditor.free.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@
name: (obj.data ? obj.data : obj.mData),
type: (obj.type ? obj.type : 'text'),
options: (obj.options ? obj.options : []),
readonly: (obj.readonly ? obj.readonly : false),
disabled: (obj.disabled ? obj.disabled : false),
msg: (obj.errorMsg ? obj.errorMsg : ''),
hoverMsg: (obj.hoverMsg ? obj.hoverMsg : ''),
pattern: (obj.pattern ? obj.pattern : '.*'),
Expand Down Expand Up @@ -437,6 +439,7 @@

// Adding readonly-fields
if (columnDefs[j].type.indexOf("readonly") >= 0) {
// type=readonly is deprecated, kept for backward compatibility
data += "<input type='text' readonly id='"
+ this._quoteattr(columnDefs[j].name)
+ "' name='"
Expand All @@ -462,33 +465,29 @@
}
}
data += "<select class='form-control" + (columnDefs[j].select2 ? ' select2' : '')
+ "' id='" + this._quoteattr(columnDefs[j].name) + "' name='" + this._quoteattr(columnDefs[j].title) + "' "
+ (columnDefs[j].multiple ? 'multiple' : '') + ">" + options
+ "' id='" + this._quoteattr(columnDefs[j].name)
+ "' name='" + this._quoteattr(columnDefs[j].title) + "' "
+ (columnDefs[j].multiple ? ' multiple ' : '')
+ (columnDefs[j].readonly ? ' readonly ' : '')
+ (columnDefs[j].disabled ? ' disabled ' : '')
+ ">" + options
+ "</select>";
}
// Adding text-inputs and errorlabels, but also new HTML5 typees (email, color, ...)
else {
data += "<input type='"
+ this._quoteattr(columnDefs[j].type)
+ "' id='"
+ this._quoteattr(columnDefs[j].name)
+ "' pattern='"
+ this._quoteattr(columnDefs[j].pattern)
+ "' title='"
+ this._quoteattr(columnDefs[j].hoverMsg)
+ "' name='"
+ this._quoteattr(columnDefs[j].title)
+ "' placeholder='"
+ this._quoteattr(columnDefs[j].title)
+ "' data-special='"
+ this._quoteattr(columnDefs[j].special)
+ "' data-errorMsg='"
+ this._quoteattr(columnDefs[j].msg)
+ "' data-uniqueMsg='"
+ this._quoteattr(columnDefs[j].uniqueMsg)
+ "' data-unique='"
+ columnDefs[j].unique
+ "'"
data += "<input type='" + this._quoteattr(columnDefs[j].type)
+ "' id='" + this._quoteattr(columnDefs[j].name)
+ "' pattern='" + this._quoteattr(columnDefs[j].pattern)
+ "' title='" + this._quoteattr(columnDefs[j].hoverMsg)
+ "' name='" + this._quoteattr(columnDefs[j].title)
+ "' placeholder='" + this._quoteattr(columnDefs[j].title)
+ "' data-special='" + this._quoteattr(columnDefs[j].special)
+ "' data-errorMsg='" + this._quoteattr(columnDefs[j].msg)
+ "' data-uniqueMsg='" + this._quoteattr(columnDefs[j].uniqueMsg)
+ "' data-unique='" + columnDefs[j].unique
+ "' "
+ (columnDefs[j].readonly ? ' readonly ' : '')
+ (columnDefs[j].disabled ? ' disabled ' : '')
+ (columnDefs[j].maxLength == false ? "" : " maxlength='" + columnDefs[j].maxLength + "'")
+ " style='overflow:hidden' class='form-control form-control-sm' value=''>";
data += "<label id='" + this._quoteattr(columnDefs[j].name) + "label"
Expand Down

0 comments on commit d45e0b4

Please sign in to comment.