Recurrence rules generator form control for Angular
Inspired and partially forked from https://github.com/Fafruch/react-rrule-generator
This is Angular form control using Bootstrap styling. It's built with the help of a great rrule.js library.
It also uses:
https://kumar-muthu.github.io/ngx-rrule/
$ npm i ngx-rrule @ng-bootstrap/ng-bootstrap rrule bootstrap
import {NgxRruleModule} from 'ngx-rrule';
@NgModule({
imports: [NgxRruleModule]
})
export class AppModule {}
Optionally, this can be added to styles section of angular.json
@import '~bootstrap/dist/css/bootstrap.css';
<form [formGroup]="myform">
<ngx-rrule formControlName="testRule"
[hideStart]="false"
[hideEnd]="false"
tz="America/New_York"
[frequency]="['Daily','Monthly','Weekly', 'Yearly']"></ngx-rrule>
</form>
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
myform: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.myform = this.formBuilder.group({
testRule: ''
});
this.myform.valueChanges.subscribe(() => {
const rRuleFormValue = this.myform.value.testRule;
// Get the rrule object.
// This is an instance of RRule. Refer to https://github.com/jakubroztocil/rrule on how to use it
console.log(rRuleFormValue.rRule);
// Optional - Raw value of the ngxRrule used internally
console.log(rRuleFormValue.raw);
});
}
}
Option | Description |
---|---|
hideStart |
(optional) Hides the start date part in the form.Defaults to |
hideEnd |
(optional) Hides the until(end) date part in the form.Defaults to |
frequency |
(required) One or many of the following recurrence options
|
tz |
(optional) Timezone. Defaults to local timezone |
MIT