Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
...
import { isORCIDValidator } from '../../shared/index';
@Component({
selector: 'user-edit-component',
templateUrl: './user-edit.component.html',
styleUrls: ['./user-edit.component.css']
})
export class UserEditComponent implements OnInit {
@Input() user:User;
urlRegexPattern: string = 'https:\/\/orcid\.org\/.*'; // Regex pattern to ensure URL starts with https://orcid.org/
// TODO Regex pattern for 16digit part following this
/* Creating form */
userForm: FormGroup;
// naming form controls as class properties means we can refer to them by name in the html template - see: https://codecraft.tv/courses/angular/forms/model-driven-validation/
...
orcid: FormControl;
...
constructor(private userService: UserService) {
}
createFormControls() {
...
this.orcid = new FormControl(this.user.orcid,[Validators.pattern(this.urlRegexPattern),isORCIDValidator]);
...
}
createForm() {
this.userForm = new FormGroup({
...
orcid: this.orcid,
...
});
}
ngOnInit() {
this.createFormControls();
this.createForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.