aitboudad on main
docs: fix v6 documentation (#33… (compare)
@aitboudad is it possible to provide functions as string for expressionProperties and then evaluate them as function where we need to use. Something like
this.fieldConfig.hideExpression =
'(model: any, formState: any, field: FormlyFieldConfig) => { if (this.fieldConfig.model.value) { return !( formState.mainModel[this.fieldConfig.model.component] && formState.mainModel[this.fieldConfig.model.component] === this.fieldConfig.model.value ); } else { return !formState.mainModel[this.fieldConfig.model.component]; } },';
Idea is to use string for expression props and then evaluate with typescript something like:
https://stackoverflow.com/questions/45153848/evaluate-typescript-from-string
thing is i need to interpolate values from this inside string like this.fieldConfig.model.value.. etc.. If i first try to execute logic simply as function and then try to stringify
this.fieldConfig.expressionProperties = JSON.stringify(this.fieldConfig.expressionProperties);
ngx formly of course complains cause we cannot use string for hideExpression.
@aitboudad. Please I want to click on any step and fire (selectionChange)="selectionChanged($event)".
<mat-horizontal-stepper (selectionChange)="selectionChanged($event)" #stepperauto>
<mat-step *ngFor="let step of field.fieldGroup; let index = index; let last = last;">
<ng-template matStepLabel>
{{ step.templateOptions.label}}
</ng-template>
<router-outlet *ngIf="index === selectedStep"></router-outlet>
</mat-step>
</mat-horizontal-stepper>
public selectedStep: number = 0;
steps: any[];
data : any[];
fields: FormlyFieldConfig[];
ngOnInit() {
////this.steps = this.route.snapshot.routeConfig.children.map(child => { return child.path }); //breaking
this.steps = this.route.snapshot.data.children.map(child => { return child.path }); //breaking
let step = this.field.fieldGroup[0];
this.router.navigate([step], { relativeTo: this.route });
}
selectionChanged(event: any) {
this.selectedStep = event.selectedIndex;
this.router.navigate([this.field.fieldGroup[this.selectedStep]],{relativeTo:this.route});
}
prePopulate(field: FormlyFieldConfig) {
field.fieldGroup = [
{
key: 'account',
type: 'payment-card-form',
expressionProperties: {
hide: () => {
console.log(this.state);
return this.state === 'selector';
},
lazyRender
to true
, it was part of v5.10.0 release (will be enabled by default in v6
)
yarn demo
I got a bunch of errors (e.g. Error: src/ui/primeng/checkbox/src/checkbox.module.ts:11:17 - error NG1010: Value at position 0 in the NgModule.declarations of FormlyCheckboxModule is not a reference
Value could not be determined statically.
or src/ui/primeng/checkbox/src/checkbox.module.ts:32:14 - error NG6002: Appears in the NgModule.imports of FormlyPrimeNGModule, but could not be resolved to an NgModule class.
). Any idea of what is going on?@aleixsuau not sure what's going on there 🤔, try to remove node_modules folder and use npm
instead of yarn:
npm install
npm run start
the doc doesn't require running the demo, so just edit the markdown files https://github.com/ngx-formly/ngx-formly/tree/main/demo/src/app/guides in case you still having those issues
@aitboudad. Please I am getting error => TypeError: validatorOption.validation is not a function. Because we are not passing ['ip'] for validation. We are using cutom type and JSON externally, and we do not want IpValidator function. See below that actually worked in stackblitz after we edited to what we want and we removed all references to IPValidator- check @farakk/angular-vkbvjn here https://stackblitz.com/edit/angular-vkbvjn?file=app%2Fapp.component.ts But it is not working in our code {
"key": "cust",
"type": "custom",
"templateOptions": {
"label": "Custom Name",
"type":"text",
"required": true
},
"validation": {
"messages": {
"required": "Please tell us your zip code!"
}
},
"validators": {
"ip2":
{
"expression": "\control => \/\d{5}\/\.test(control\.value)\",
"message": "Not a valid IP Address"
}
}
}
ngOnInit() {
if (this.field.validators) {
JSON.parse(JSON.stringify(this.formControl
.setValidators(JSON.parse(this.field?.validators?.validation))));
phoneCtrl.setValue(value);
phoneCtrl.markAsPristine();
phoneCtrl.markAsUntouched();