Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit ba336ec

Browse files
committed
Bind callback functions for chips and select by using statement
1 parent b334be4 commit ba336ec

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/types/chips/chips.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export default (formlyConfigProvider) => {
2121
attribute: 'delete-hint'
2222
},
2323
onAdd: {
24-
bound: 'md-on-add'
24+
statement: 'md-on-add'
2525
},
2626
onRemove: {
27-
bound: 'md-on-remove'
27+
statement: 'md-on-remove'
2828
},
2929
onSelect: {
30-
bound: 'md-on-select'
30+
statement: 'md-on-select'
3131
}
3232
}
3333
},

src/types/select/select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export default (formlyConfigProvider) => {
1515
bound: 'ng-disabled'
1616
},
1717
onClose: {
18-
bound: 'md-on-close'
18+
statement: 'md-on-close'
1919
},
2020
onOpen: {
21-
bound: 'md-on-open'
21+
statement: 'md-on-open'
2222
}
2323
}
2424
},

tests/types/chips-spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ describe('formlyMaterial - chips type', () => {
1313
let fieldScope;
1414
const theme = 'custom';
1515

16-
function onAdd() {
16+
function onAdd($modelValue, $inputValue, scope, $event) {
1717
return true;
1818
}
1919

20-
function onRemove() {
20+
function onRemove($modelValue, $inputValue, scope, $event) {
2121
return true;
2222
}
2323

24-
function onSelect() {
24+
function onSelect($modelValue, $inputValue, scope, $event) {
2525
return true;
2626
}
2727
//
@@ -95,17 +95,17 @@ describe('formlyMaterial - chips type', () => {
9595
});
9696

9797
it('should have onAdd callback', () => {
98-
expect(element.attr('md-on-add')).toBe(`options.templateOptions['onAdd']`);
98+
expect(element.attr('md-on-add')).toBe(`options.templateOptions['onAdd'](model[options.key], options, this, $event)`);
9999
expect(fieldScope.options.templateOptions.onAdd).toBe(onAdd);
100100
});
101101

102102
it('should have onRemove callback', () => {
103-
expect(element.attr('md-on-remove')).toBe(`options.templateOptions['onRemove']`);
103+
expect(element.attr('md-on-remove')).toBe(`options.templateOptions['onRemove'](model[options.key], options, this, $event)`);
104104
expect(fieldScope.options.templateOptions.onRemove).toBe(onRemove);
105105
});
106106

107107
it('should have onSelect callback', () => {
108-
expect(element.attr('md-on-select')).toBe(`options.templateOptions['onSelect']`);
108+
expect(element.attr('md-on-select')).toBe(`options.templateOptions['onSelect'](model[options.key], options, this, $event)`);
109109
expect(fieldScope.options.templateOptions.onSelect).toBe(onSelect);
110110
});
111111

tests/types/select-spec.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ describe('formlyMaterial - select type', () => {
1717
let field;
1818
const theme = 'custom';
1919

20+
function onClose($modelValue, $inputValue, scope, $event) {
21+
return true;
22+
}
23+
24+
function onOpen($modelValue, $inputValue, scope, $event) {
25+
return true;
26+
}
2027
//
2128
// helpers
2229
//
@@ -30,8 +37,8 @@ describe('formlyMaterial - select type', () => {
3037
theme,
3138
label: 'test field',
3239
multiple: true,
33-
onClose: () => true,
34-
onOpen: () => true,
40+
onClose: onClose,
41+
onOpen: onOpen,
3542
options: [{
3643
name: 'first',
3744
nameUp: 'FIRST',
@@ -119,12 +126,14 @@ describe('formlyMaterial - select type', () => {
119126

120127
it('should be able to bind md-on-close', () => {
121128
compile();
122-
expect(element.attr('md-on-close')).toBe(`options.templateOptions['onClose']`);
129+
expect(element.attr('md-on-close')).toBe(`options.templateOptions['onClose'](model[options.key], options, this, $event)`);
130+
expect(elementScope.options.templateOptions.onClose).toBe(onClose);
123131
});
124132

125133
it('should be able to bind md-on-open', () => {
126134
compile();
127-
expect(element.attr('md-on-open')).toBe(`options.templateOptions['onOpen']`);
135+
expect(element.attr('md-on-open')).toBe(`options.templateOptions['onOpen'](model[options.key], options, this, $event)`);
136+
expect(elementScope.options.templateOptions.onOpen).toBe(onOpen);
128137
});
129138

130139
it('should be able to be disabled', () => {

0 commit comments

Comments
 (0)