1- /* eslint-disable */
1+ import { computed , watch } from 'vue' ;
2+ import { hasValue , isArray , isObject } from '../core/utils/helpers' ;
23
3- import { watch } from 'vue ' ;
4- import { hasValue } from '../core/utils/helpers ' ;
4+ import { useInputValidation } from '@/composables/use-validation ' ;
5+ import { BindingObject } from '..' ;
56
67export function useInputEvents ( props : any , emit : any ) {
8+ const { validate } = useInputValidation ( props , emit ) ;
9+
710 function onChange ( $event ) : void {
811 if ( props . control && hasValue ( $event . target . value ) ) {
912 $event . stopImmediatePropagation ( ) ;
1013
14+ validate ( ) ;
1115 emit ( 'change' , {
1216 name : props . control . name ,
13- value : $event . target . value
17+ value : $event . target . value ,
1418 } ) ;
1519 }
1620 }
@@ -25,25 +29,41 @@ export function useInputEvents(props: any, emit: any) {
2529 }
2630 }
2731 function onFocus ( ) : void {
28- emit ( 'focus' ) ;
32+ emit ( 'focus' , { name : props . control . name } ) ;
2933 }
3034 function onBlur ( ) : void {
31- emit ( 'blur' ) ;
35+ emit ( 'blur' , { name : props . control . name } ) ;
36+ validate ( ) ;
3237 }
3338
34- watch ( ( ) => props ?. control ?. value , ( curr , prev ) => {
35- if ( prev === undefined && hasValue ( curr ) ) {
36- emit ( 'change' , {
37- name : props . control . name ,
38- value : props . control . value
39- } ) ;
39+ const getClasses = computed ( ( ) => {
40+ const classes = [ 'form-control' ] ;
41+ if ( isArray ( props . control . customClass ) ) {
42+ return [ ...classes , ...( props . control . customClass as BindingObject [ ] ) ] ;
43+ }
44+ if ( isObject ( props . control . customClass ) ) {
45+ return [ ...classes , props . control . customClass ] ;
4046 }
41- } )
47+ return [ classes , props . control . customClass ] ;
48+ } ) ;
49+
50+ watch (
51+ ( ) => props ?. control ?. value ,
52+ ( curr , prev ) => {
53+ if ( prev === undefined && hasValue ( curr ) ) {
54+ emit ( 'change' , {
55+ name : props . control . name ,
56+ value : props . control . value ,
57+ } ) ;
58+ }
59+ } ,
60+ ) ;
4261
4362 return {
4463 onFocus,
4564 onChange,
4665 onBlur,
4766 onCheck,
67+ getClasses,
4868 } ;
4969}
0 commit comments