mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Editable: validate function now includes a contenteditable element parameter
This commit is contained in:
parent
a6e8fcc84b
commit
3bf7700fec
@ -371,6 +371,7 @@ td.no-edit, span.no-edit {
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Set this option to be a global function, or an object containing a column index, or class name of the desired column</li>
|
<li>Set this option to be a global function, or an object containing a column index, or class name of the desired column</li>
|
||||||
<li>A <code>columnIndex</code> is now included in the function parameters</li>
|
<li>A <code>columnIndex</code> is now included in the function parameters</li>
|
||||||
|
<li>A <code>$element</code> parameter has been included which contains the contenteditable element. To get the table cell, use <code>$element.closest('td');</code></li>
|
||||||
</ul>
|
</ul>
|
||||||
This function must return either a string containing the modified content or <code>false</code> to revert the content back to it's original value. Example:
|
This function must return either a string containing the modified content or <code>false</code> to revert the content back to it's original value. Example:
|
||||||
<pre class="prettyprint lang-js">$(function(){
|
<pre class="prettyprint lang-js">$(function(){
|
||||||
@ -379,7 +380,7 @@ td.no-edit, span.no-edit {
|
|||||||
widgets : ['editable'],
|
widgets : ['editable'],
|
||||||
widgetOptions : {
|
widgetOptions : {
|
||||||
// global validate function
|
// global validate function
|
||||||
editable_validate : function(txt, orig, columnIndex){
|
editable_validate : function(txt, orig, columnIndex, $element){
|
||||||
// only allow one word
|
// only allow one word
|
||||||
var t = /\s/.test(txt) ? txt.split(/\s/)[0] : txt;
|
var t = /\s/.test(txt) ? txt.split(/\s/)[0] : txt;
|
||||||
return t ? t : false;
|
return t ? t : false;
|
||||||
@ -392,12 +393,12 @@ td.no-edit, span.no-edit {
|
|||||||
widgetOptions : {
|
widgetOptions : {
|
||||||
// validate function per column
|
// validate function per column
|
||||||
editable_validate : {
|
editable_validate : {
|
||||||
0 : function(txt, orig, columnIndex){
|
0 : function(txt, orig, columnIndex, $element){
|
||||||
// allow up to two words
|
// allow up to two words
|
||||||
var t = txt.split(' ');
|
var t = txt.split(' ');
|
||||||
return t.length > 2 ? t[0] + (t[1] ? ' ' + t[1] : '') : txt;
|
return t.length > 2 ? t[0] + (t[1] ? ' ' + t[1] : '') : txt;
|
||||||
},
|
},
|
||||||
'.price' : function(txt, orig, columnIndex) {
|
'.price' : function(txt, orig, columnIndex, $element) {
|
||||||
// make sure the price column(s) are using a number
|
// make sure the price column(s) are using a number
|
||||||
return isNaN( txt.replace(/[$,\s]/g, '') ) ? false : txt;
|
return isNaN( txt.replace(/[$,\s]/g, '') ) ? false : txt;
|
||||||
}
|
}
|
||||||
|
@ -139,9 +139,9 @@
|
|||||||
valid = $this.html();
|
valid = $this.html();
|
||||||
|
|
||||||
if (typeof(validate) === "function") {
|
if (typeof(validate) === "function") {
|
||||||
valid = validate( $this.html(), $this.data('original'), column );
|
valid = validate( $this.html(), $this.data('original'), column, $this );
|
||||||
} else if (typeof (validate = $.tablesorter.getColumnData( table, validate, column )) === 'function') {
|
} else if (typeof (validate = $.tablesorter.getColumnData( table, validate, column )) === 'function') {
|
||||||
valid = validate( $this.html(), $this.data('original'), column );
|
valid = validate( $this.html(), $this.data('original'), column, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( t && valid !== false ) {
|
if ( t && valid !== false ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user