Search code examples
jqueryjeditablemaxlength

jeditable dynamic maxlength


following up to this question: jquery select and use part of class name

i thought to use this way to dynamically assign a maxlength to the jeditable script (i assign a special class to each element startig with edit_*, where the star is the maxlength):

$("[class^='edit_']").editable('url', {
    id          : $(this).attr('id'),
    maxlength   : $("[class^='edit_']").on('click',function() {
            return $(this).attr('class').split(' ')[0].split('_')[1];
    }),
});

problem is that while the function itself works if used separately, it doesn't work inside the above script. I even tried to return a number manually (ex. return 2) and it works...what's the trick?


Solution

  • ok, for those who will be landing here...i solved this way:

    $("[class^='edit_']").each( function() {
        var ml = $(this).attr('class').split(' ')[0].split('_')[1];
        $(this).editable('[url]', {
            [...]
            maxlength   : ml,
        });
    });