2021-04-21 02:38:00 -05:00
|
|
|
import { isArray } from 'lodash';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-11-09 01:37:16 -06:00
|
|
|
import coreModule from './core_module';
|
2015-09-11 03:54:56 -05:00
|
|
|
|
2015-09-12 04:49:14 -05:00
|
|
|
export function arrayJoin() {
|
2017-12-20 05:33:33 -06:00
|
|
|
'use strict';
|
2015-09-11 14:04:02 -05:00
|
|
|
|
2015-09-11 03:54:56 -05:00
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
2019-04-28 02:58:12 -05:00
|
|
|
link: (scope: any, element: any, attr: any, ngModel: any) => {
|
|
|
|
function split_array(text: string) {
|
2017-12-20 05:33:33 -06:00
|
|
|
return (text || '').split(',');
|
2015-09-11 03:54:56 -05:00
|
|
|
}
|
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
function join_array(text: string) {
|
2021-04-21 02:38:00 -05:00
|
|
|
if (isArray(text)) {
|
2019-04-15 05:11:52 -05:00
|
|
|
return ((text || '') as any).join(',');
|
2015-09-11 03:54:56 -05:00
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModel.$parsers.push(split_array);
|
|
|
|
ngModel.$formatters.push(join_array);
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2015-09-11 03:54:56 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('arrayJoin', arrayJoin);
|