Skip to content

Instantly share code, notes, and snippets.

@theotherdy
Last active July 23, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theotherdy/a51ed7cbbb63c2e288481614b9a288e6 to your computer and use it in GitHub Desktop.
Save theotherdy/a51ed7cbbb63c2e288481614b9a288e6 to your computer and use it in GitHub Desktop.
...
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