Skip to content

Instantly share code, notes, and snippets.

@travist
Created October 14, 2019 19:36
Show Gist options
  • Save travist/f35298a8a807750df7d88eeea2fe5998 to your computer and use it in GitHub Desktop.
Save travist/f35298a8a807750df7d88eeea2fe5998 to your computer and use it in GitHub Desktop.
Add Submission Access to Form Manager
  • ng g component form/create
  • Add the following code
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { FormioAlerts } from 'angular-formio';
import { FormioAuthService } from 'angular-formio/auth';
import { FormManagerService, FormManagerEditComponent, FormManagerConfig } from 'angular-formio/manager';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-create',
templateUrl: './create.component.html',
styleUrls: ['./create.component.scss']
})
export class CreateComponent extends FormManagerEditComponent implements OnInit {
constructor(
public service: FormManagerService,
public router: Router,
public route: ActivatedRoute,
public config: FormManagerConfig,
public ref: ChangeDetectorRef,
public alerts: FormioAlerts,
public auth: FormioAuthService
) {
super(service, router, route, config, ref, alerts);
auth.accessReady.then((access) => {
let authRole = null;
for (const name in access.roles) {
if (name === 'authenticated') {
authRole = access.roles[name];
break;
}
}
this.form.submissionAccess = [
{
type: 'create_all',
roles: [authRole._id]
},
{
type: 'read_all',
roles: [authRole._id]
}
];
});
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { FormioGrid } from 'angular-formio/grid';
import { FormioModule } from 'angular-formio';
import { FormManagerModule, FormManagerRoutes, FormManagerService, FormManagerConfig } from 'angular-formio/manager';
import { CreateComponent } from './create/create.component';
@NgModule({
imports: [
CommonModule,
FormioGrid,
FormioModule,
FormManagerModule,
RouterModule.forChild(FormManagerRoutes({
formCreate: CreateComponent
}))
],
declarations: [
CreateComponent
],
providers: [
FormManagerService,
{provide: FormManagerConfig, useValue: {
tag: 'common'
}}
]
})
export class FormModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment