angularangular-ngselect

Limit max length of tag in Angular ng-select


Having ng-select component-> https://ng-select.github.io/ng-select#/tags (Tags without dropdown panel )

I want to know if there is something similar to <input maxlength="255">. Because if I try maxlength, or size, it does not work.

It would be desirable if after the character 255 the insertion of additional characters would be interrupted, like in <input>

Thanks in advance


Solution

  • ng-select doesn't seem to support that yet, but you can do something like:

     <ng-select 
    ...
    [addTag]="addTagFn">
    </ng-select>
    
    addTagFn = (term) => {
        if (// check here if length of term matches 255 or less) {
            return term;
        }
        return null;
    }