Parcourir la source

Merging in more changes from AMP

Richard Knight il y a 5 ans
Parent
commit
72299fab50

+ 0 - 1
src/app/dynaform/components/_abstract/custom-input.component.ts

@@ -3,7 +3,6 @@ import { NativeInputComponent } from './native-input.component';
 
 export abstract class CustomInputComponent extends NativeInputComponent implements ControlValueAccessor {
 
-	
 	propagateChange = (_: any) => {};
 
 	writeValue(value: any): void {};

+ 1 - 1
src/app/dynaform/dynaform.module.ts

@@ -24,7 +24,7 @@ import { ffcArr } from './components'; // ffcArr = Form Field Components Array,
 		RouterModule.forChild([]),
 		// NgbModule,
 		// DateInputsModule
-		ClarityModule,
+		ClarityModule
 	],
 	declarations: [
 		DynaformComponent,

+ 2 - 2
src/app/dynaform/index.ts

@@ -3,6 +3,6 @@ export { DynaformComponent } from './dynaform.component';
 export { DynaformService } from './services/dynaform.service';
 export { ModelMapperService } from './services/model-mapper.service';
 export { standardModifiers, standardTransformer, toArrTag, arrayPad, arrayToMeta, excludeFields, makeAsyncTest } from './utils';
-// export { FRIENDLY_VALIDATION_ERRORS } from './config/validation-messages.config';
-// export { FriendlyValErrors } from './interfaces';
+export { FRIENDLY_VALIDATION_ERRORS } from './config/validation-messages.config';
+export { FriendlyValErrors } from './interfaces';
 

+ 13 - 6
src/app/dynaform/models/field.model.ts

@@ -105,10 +105,10 @@ abstract class SimpleField {
 				const boundFn = this.asyncValidators.bind(context);
 				this.asyncValidators = boundFn;
 			} else {
-				for (const i in this.asyncValidators) {
-					const boundFn = this.asyncValidators[i].bind(context);
+				this.asyncValidators.forEach((valFn, i) => {
+					const boundFn = valFn.bind(context);
 					this.asyncValidators[i] = boundFn;
-				}
+				});
 			}
 		}
 	}
@@ -176,6 +176,13 @@ class PasswordField extends SimpleField {
 class SelectField extends OptionsField {
 	type = 'Select';
 	link?: ILink;
+	constructor(meta: IOptionsFieldMetaData, context?: any) {
+		super(meta, context);
+		// If there's only one possible choice set the value
+		if (this.options.length === 1) {
+			this.default = this.options[0].value as string;
+		}
+	}
 }
 
 class RadioField extends OptionsField {
@@ -334,9 +341,9 @@ class RepeatingContainer {
 			this.initialRepeat = containerMeta.meta.length;
 		}
 		this.meta = containerMeta.meta.map((m, i) => new Container({
-			name: `${this.prefix}${i+1}`,
+			name: `${this.prefix}${i + 1}`,
 			meta: m,
-			button: unCamelCase(`${this.prefix}${i+1}`),
+			button: unCamelCase(`${this.prefix}${i + 1}`),
 			focussed: this.display === 'SINGLE' ? i === 0 : true
 		}));
 	}
@@ -407,7 +414,7 @@ class DisplayField extends SimpleField {
 // Interfaces
 export {
 	IOption, ILink
-}
+};
 
 // Classes
 export {