Search code examples
jqueryjeditable

JEditable: format number before edit


I'm currently using JEditable to edit a table of numbers. I use javascript to format my numbers to the French standard, with a space every three digits (eg. 1234567 becomes 1 234 567). These spaces are represented by  .

Hence if I click to edit the number 1 234 567 it will come as 1 234 567 in the textbox. Is there a way to add a callback to the JEditable click event so I can replace the spaces by blanks? I do it already the other way around when the edit is finished but I don't know if there is a callback for the click event.

Thank you!


Solution

  • You can use function as dataparameter to alter content before it is edited. For example:

    $(".edit").editable('http://example.com/save', {
        cancel: 'Cancel',
        submit: 'OK',
        data: function (value, settings) {
            return value.replace(/ /gi, '');
        } 
    });