rauchg / TextboxList

MooTools tokenizer
100 stars 35 forks source link

No clear functionality #3

Open carcus88 opened 13 years ago

carcus88 commented 13 years ago

It would be nice to be able to clear the box. Here is a function to do that

/**
 * Clear the box and return all the values that where cleared
 */
var clear = function() {
    element.val('')
    var values = [];
    list.children().each(function(){
        var bit = getBit(this);
        if (!bit.is('editable')) values.push(bit.remove());
    });
   return values;
}
bragboy commented 12 years ago

Hey, carcus88 - Thank you very much for you tweak !

Kitof commented 12 years ago

Thanks a lot.

I just added a little correction to avoid trouble with unique constraint :

/**
 * Clear the box and return all the values that where cleared
 */
var clear = function() {
    element.val('')
    var values = [];
    list.children().each(function(){
        var bit = getBit(this);
        if (!bit.is('editable')) values.push(bit.remove());
    });
   index = [];
   return values;
}