Skip to content

Commit fcc1fb0

Browse files
committed
Implemented formatSelected configuration callback
1 parent 2a054e9 commit fcc1fb0

37 files changed

+239823
-609
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 1.1.0 - 2020-12-18
4+
> :exclamation: **Deprecations have been added in this version**
5+
* Implemented formatSelected configuration callback.
6+
This makes the customTemplate.label obsolete. The whole type of customTemplate will probably change to TemplateRef in v2.
7+
8+
You will be notified during development of this deprecation by console warning, and only when you are using a custom template with a label defined.
9+
The warning is turned off in production
10+
11+
## 1.0.1 - 2020-12-18
12+
* Accepted installs from angular version 9 and above
13+
314
## 0.3.2 - 2020-05-10
415

516
### Fixes

README.md

+37-9
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,34 @@ Add the `[ncNgxMention]` directive to your input or textarea element
3737
<input type="text" [ncNgxMention]="items">
3838
```
3939

40-
Where `items` is a array of objects defined like interface [NgxMention](projects/src/lib/ngx-mention/src/lib/ngx-mention.config.ts)
40+
Where `items` is a array of objects defined like the type [NgxMentions](projects/src/lib/ngx-mention/src/lib/ngx-mention.config.ts)
41+
NgxMentions is a simple type that maps your own given type into ngx-mention array type if you want it to.
42+
43+
An example of defining your own type is shown below:
44+
45+
```typescript
46+
public ngxMentions: NgxMentions<type or interface of your choosing> = [];
47+
```
4148

4249
### Configuration options
4350

4451
The following configuration options are available
4552

46-
Option | Default | Description
47-
--- | --- | ---
48-
denotationCharacter | @ | Trigger on which the mention list is activated
49-
minimalCharacters | 0 | Minimal amount of characters before search is activated
50-
disableSearch | false | Set this to true for async search (using the search Output)
51-
dropUp | false | Mention list should be a drop up instead of dropdown
53+
Option | Default | Description
54+
--- | --- | ---
55+
denotationCharacter | @ | Trigger on which the mention list is activated
56+
minimalCharacters | 0 | Minimal amount of characters before search is activated
57+
disableSearch | false | Set this to true for async search (using the search Output)
58+
dropUp | false | Mention list should be a drop up instead of dropdown
59+
formatSelected | item.value | Function to format selected item before inserting text
5260

5361
For example
5462
```html
5563
<input type="text" [ncNgxMention]="items" [ngxMentionConfig]="{denotationCharacter: '$', minimalCharacters: 3}">
5664
```
5765

5866
### Custom templates
59-
It is possible to add a custom template to change the way items are visible. The given label will be used to retrieve the correct name to be visible in the input field.
67+
It is possible to add a custom template to change the way items are visible.
6068

6169
```Html
6270
<ng-template #customTemplate let-item="item">
@@ -66,10 +74,30 @@ It is possible to add a custom template to change the way items are visible. The
6674
<input
6775
type="text"
6876
[ncNgxMention]="[{id: 1, username: 'John'}, {id: 2, username: 'Doe'}]"
69-
[customTemplate]="{ template: customTemplate, label: 'username' }"
77+
[customTemplate]="{ template: customTemplate }"
7078
/>
7179
```
7280

81+
By default ngx-mention will expect a array structure defined like the interface [NgxMention](projects/src/lib/ngx-mention/src/lib/ngx-mention.config.ts).
82+
By default ngx-mention will look to a property value which will parsed into the input or textarea.
83+
84+
You can alter this behavior by using the formatSelected configuration.
85+
86+
An example for the above structure would be:
87+
88+
```typescript
89+
interface OtherStructure {
90+
id: number,
91+
username: string
92+
}
93+
94+
const configuration: NgxMentionConfig<OtherStructure> = {
95+
formatSelected: (item) => {
96+
// In here item will be typed as OtherStructure
97+
return item.username;
98+
}
99+
}
100+
```
73101

74102
### Output events
75103
Output | Description

0 commit comments

Comments
 (0)