hendisantika / jquery-datatables-editable

Automatically exported from code.google.com/p/jquery-datatables-editable
0 stars 1 forks source link

Validation for types other than text, select, textarea? #129

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I would like to use a jeditable-user-defined type AND validation on this type. 
This currently only seems to be possible with modification of 
jquery.dataTables.editable.js sources, see below.

What steps will reproduce the problem?
1. Make a jeditable user-defined type (for example the jquery-ui datepicker 
that relies on an ordinary text input field:

$.editable.addInputType('myDate', {
    element : function(settings, original) {
        var input = $('<input>');
        if (settings.width  != 'none') {
            input.width(settings.width);
        }
        if (settings.height != 'none') {
            input.height(settings.height);
        }
        input.attr('autocomplete','off');
        $(this).append(input);
        return(input);
    },
    plugin : function(settings, original) {
        /* Workaround for missing parentNode in IE */
        var form = this;
        settings.onblur = 'ignore';
        $(this).find('input').datepicker({
            onSelect: function(dateText) {
                $(form).submit();
            }
        });
    }
});

2. Set the desired aoColumn properly: 

{ type: 'myDate', oValidationOptions: { rules: { value: { regEx: 
/^[0-9]{4}-((1[012])|(0?[1-9]))-(([0-2]?[0-9])|(3[01]))$/ } }, messages: { 
value: { regEx: "Bitte Datum im Format JJJJ-MM-TT eingeben." } } } , etc. etc.}

3. Debugging seems to show that in file jquery.dataTables.editable.js,
line 209:

>> if(settings.type == "text" || settings.type == "select" || settings.type == 
"textarea")

... validation will only be performed if the aoColumn-type is one of the three 
shown above(?).

On the other hand, my type has to be some used-defined type, i. e. 'myDate', to 
get the datepicker working with $.editable.addInputType.

In my opinion, validation DOES make sense in this case: The user can
a) use the datepicker to fill the input field properly
b) directly type a date into the input field - which we should validate, of 
course.

Any ideas how to solve this without having to modify the code to 

>> if(settings.type == "text" || settings.type == "select" || settings.type == 
"textarea" || settings.type == "myDate")

?

What version of the product are you using? On what operating system?

Windows 7, Firefox 10.0.2

Original issue reported on code.google.com by franzjos...@gmail.com on 30 Aug 2012 at 12:48

GoogleCodeExporter commented 8 years ago
Thank you so much for solving my current problem :-)

Original comment by gm4sgn...@googlemail.com on 8 Jan 2015 at 9:35