This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +25
-12
lines changed Expand file tree Collapse file tree 4 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -53,10 +53,8 @@ import {
5353 EmailInput ,
5454 FormValidation ,
5555 PasswordInput ,
56- TextAreaInput ,
5756 CheckboxInput ,
5857 RadioInput ,
59- InputBase ,
6058 email ,
6159 pattern ,
6260 ColorInput ,
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ import DynamicInput from '../dynamic-input/DynamicInput.vue';
5151
5252import { InputBase , FormControl } from ' ../../core/models' ;
5353import { dynamicFormsSymbol } from ' ../../useApi' ;
54+ import { removeEmpty } from ' ../../core/utils/helpers' ;
5455
5556const props = {
5657 form: {
@@ -145,9 +146,9 @@ export default defineComponent({
145146 }
146147 });
147148
148- function valueChange(changedValue : any ) {
149+ function valueChange(changedValue ) {
149150 Object .assign (formValues , changedValue );
150- ctx .emit (' changed' , formValues );
151+ ctx .emit (' changed' , removeEmpty ( formValues ) );
151152 }
152153
153154 function mapControls(empty ? ) {
Original file line number Diff line number Diff line change @@ -25,12 +25,18 @@ export type InputType =
2525 | UrlInput
2626 | CustomInput ;
2727
28+ type ValidationError = {
29+ text : string ;
30+ // eslint-disable-next-line
31+ value : any ;
32+ } ;
33+
2834type ValidationErrors = {
29- [ key : string ] : any ;
35+ [ key : string ] : ValidationError ;
3036} ;
3137
3238interface ValidatorFn {
33- ( control : FormControl < any > | undefined ) : ValidationErrors | null ;
39+ ( control : FormControl | undefined ) : ValidationErrors | null ;
3440}
3541
3642export interface FormValidation {
@@ -39,7 +45,7 @@ export interface FormValidation {
3945}
4046
4147export interface InputBase {
42- value : any ;
48+ value : boolean | string ;
4349 name : string ;
4450 label : string ;
4551 disabled ?: boolean ;
@@ -53,10 +59,6 @@ export type TextInput = InputBase & {
5359 type : 'text' ;
5460} ;
5561
56- /* export interface EmailInput extends InputBase<string> {
57- type: 'email';
58- } */
59-
6062export type NumberInput = InputBase & {
6163 min ?: number ;
6264 max ?: number ;
@@ -65,7 +67,7 @@ export type NumberInput = InputBase & {
6567 type : 'number' ;
6668} ;
6769
68- export type SelectInput < T = any > = InputBase & {
70+ export type SelectInput < T = boolean | string > = InputBase & {
6971 type : 'select' ;
7072 value : T ;
7173 options ?: { key : string ; value : string ; disabled ?: boolean } [ ] ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable */
12export const { assign, entries, values, keys } = Object ;
23
34export const slugify = ( text : string ) : string =>
@@ -23,6 +24,17 @@ export const isEmpty = (entry: any) => {
2324 }
2425} ;
2526
27+ export const removeEmpty = obj =>
28+ Object . keys ( obj )
29+ . filter ( k => obj [ k ] != null ) // Remove undef. and null.
30+ . reduce (
31+ ( newObj , k ) =>
32+ typeof obj [ k ] === 'object'
33+ ? { ...newObj , [ k ] : removeEmpty ( obj [ k ] ) } // Recurse.
34+ : { ...newObj , [ k ] : obj [ k ] } , // Copy value.
35+ { } ,
36+ ) ;
37+
2638export const mockAsync = ( success , timeout , value ) => {
2739 return new Promise ( ( resolve , reject ) => {
2840 setTimeout ( ( ) => {
You can’t perform that action at this time.
0 commit comments