v1.0

parent 7c087f2e
...@@ -7,3 +7,7 @@ ...@@ -7,3 +7,7 @@
width: 40px; width: 40px;
padding-top: 10px; padding-top: 10px;
} }
textarea.ng-invalid.ng-touched {
border: 1px solid red;
}
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
class="form-control" class="form-control"
[(ngModel)]="displayC.components[index].input" [(ngModel)]="displayC.components[index].input"
></textarea> ></textarea>
<span class="help-block" *ngIf="!inputext.valid && inputext.touched">Username should be between 6 and 12 character long. It should contain only alphabets and digits.</span> <span class="help-block" *ngIf="!inputext.valid && inputext.touched">{{error}}</span>
</form> </form>
</div> </div>
...@@ -41,12 +41,14 @@ ...@@ -41,12 +41,14 @@
<div class="row"> <div class="row">
<div class="col-sm-12" style="padding: 5px"> <div class="col-sm-12" style="padding: 5px">
<form [formGroup]="registerForm">
<textarea <textarea
#input2 #input2
formControlName="inputext"
[placeholder]="displayC.components[index].placeholder" [placeholder]="displayC.components[index].placeholder"
[style.background]=displayC.components[index].background [style.background]=displayC.components[index].background
[style.text-align]="displayC.components[index].align" [style.text-align]="displayC.components[index].align"
[style.color]=displayC.components[index].textColor [style.color]=displayC.components[index].textcolor
style=" style="
display:table-cell; display:table-cell;
width:100%; width:100%;
...@@ -57,5 +59,8 @@ ...@@ -57,5 +59,8 @@
class="form-control" class="form-control"
[(ngModel)]="displayC.components[index].input" [(ngModel)]="displayC.components[index].input"
></textarea> ></textarea>
<span class="help-block" *ngIf="!inputext.valid && inputext.touched">{{error}}</span>
</form>
</div> </div>
</div> </div>
...@@ -51,37 +51,49 @@ export class DetailInputViewComponent implements OnInit { ...@@ -51,37 +51,49 @@ export class DetailInputViewComponent implements OnInit {
this.ischanged = true; this.ischanged = true;
} }
if (this.displayC.components[this.index].validatorsMin) { if (this.displayC.components[this.index].validatorsMin >= 0) {
console.log('--1--');
this.error += ('This field should have minimum length of ' + this.displayC.components[this.index].validatorsMin + '\n'); this.error += ('This field should have minimum length of ' + this.displayC.components[this.index].validatorsMin + '\n');
} }
if (this.displayC.components[this.index].validatorsMax) { if (this.displayC.components[this.index].validatorsMax >= 0) {
console.log('--2--');
this.error += ('This field should have maximum length of ' + this.displayC.components[this.index].validatorsMax + '\n'); this.error += ('This field should have maximum length of ' + this.displayC.components[this.index].validatorsMax + '\n');
} }
if (this.displayC.components[this.index].validatorsReq) { if (this.displayC.components[this.index].validatorsReq) {
console.log('--3--');
this.error += ('This field is compulsory \n'); this.error += ('This field is compulsory \n');
} }
if (this.displayC.components[this.index].validatorsEmail) { if (this.displayC.components[this.index].validatorsEmail) {
console.log('--4--');
this.error += ('Input valid email \n'); this.error += ('Input valid email \n');
} }
if (this.displayC.components[this.index].validatorsIsAlphaNumeric) { if (this.displayC.components[this.index].validatorsIsAlphaNumeric) {
console.log('--5--');
this.error += ('Only alphanumerics are allowed \n'); this.error += ('Only alphanumerics are allowed \n');
} }
if (this.displayC.components[this.index].validatorsIsDigit) { if (this.displayC.components[this.index].validatorsIsDigit) {
console.log('--6--');
this.error += ('Only digits are allowed \n'); this.error += ('Only digits are allowed \n');
} }
if (this.displayC.components[this.index].validatorsIsAlphabetic) { if (this.displayC.components[this.index].validatorsIsAlphabetic) {
console.log('--7--');
this.error += ('Only alphabets are allowed \n'); this.error += ('Only alphabets are allowed \n');
} }
if (this.displayC.components[this.index].validatorsIsSmall) { if (this.displayC.components[this.index].validatorsIsSmall) {
console.log('--8--');
this.error += ('Only lowercase alphabets are allowed \n'); this.error += ('Only lowercase alphabets are allowed \n');
} }
if (this.displayC.components[this.index].validatorsIsCapital) { if (this.displayC.components[this.index].validatorsIsCapital) {
console.log('--9--');
this.error += ('Only uppercase alphabets are allowed \n'); this.error += ('Only uppercase alphabets are allowed \n');
} }
if (this.displayC.components[this.index].validatorsPattern) { if (this.displayC.components[this.index].validatorsPattern) {
console.log('--10--');
this.error += ('Make sure you enter valid pattern ' + this.displayC.components[this.index].validatorsPattern + '\n'); this.error += ('Make sure you enter valid pattern ' + this.displayC.components[this.index].validatorsPattern + '\n');
} }
console.log(this.error);
console.log('length : ' + (this.displayC.components[this.index].title.trim().length < 1)); console.log('length : ' + (this.displayC.components[this.index].title.trim().length < 1));
if (this.displayC.components[this.index].title.trim().length < 1) { if (this.displayC.components[this.index].title.trim().length < 1) {
this.discrTemp = 'Click to add header'; this.discrTemp = 'Click to add header';
......
...@@ -7,3 +7,7 @@ ...@@ -7,3 +7,7 @@
width: 40px; width: 40px;
padding-top: 10px; padding-top: 10px;
} }
input.ng-invalid.ng-touched {
border: 1px solid red;
}
...@@ -38,20 +38,25 @@ ...@@ -38,20 +38,25 @@
<div class="row"> <div class="row">
<div class="col-sm-12" style="padding: 5px"> <div class="col-sm-12" style="padding: 5px">
<input <form [formGroup]="registerForm">
#input2 <input
[placeholder]="displayC.components[index].placeholder" #input2
[style.background]=displayC.components[index].background formControlName="inputext"
[style.text-align]="displayC.components[index].align" [placeholder]="displayC.components[index].placeholder"
[style.color]=displayC.components[index].textColor [style.background]=displayC.components[index].background
style=" [style.text-align]="displayC.components[index].align"
[style.color]=displayC.components[index].textcolor
style="
display:table-cell; display:table-cell;
width:100%; width:100%;
font-size: 15px; font-size: 15px;
" "
type="text" type="text"
class="form-control" class="form-control"
[(ngModel)]="displayC.components[index].input" [(ngModel)]="displayC.components[index].input"
/> />
<span class="help-block" *ngIf="!inputext.valid && inputext.touched">{{error}}</span>
</form>
</div> </div>
</div> </div>
...@@ -2,6 +2,7 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} f ...@@ -2,6 +2,7 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} f
import {DataService} from '../../../services/data.service'; import {DataService} from '../../../services/data.service';
import {DisplayComponentService} from '../../../services/display-component.service'; import {DisplayComponentService} from '../../../services/display-component.service';
import {InputComponentService} from '../../../services/input-component.service'; import {InputComponentService} from '../../../services/input-component.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({ @Component({
selector: 'app-text-input-view', selector: 'app-text-input-view',
...@@ -9,6 +10,9 @@ import {InputComponentService} from '../../../services/input-component.service'; ...@@ -9,6 +10,9 @@ import {InputComponentService} from '../../../services/input-component.service';
styleUrls: ['./text-input-view.component.css'] styleUrls: ['./text-input-view.component.css']
}) })
export class TextInputViewComponent implements OnInit { export class TextInputViewComponent implements OnInit {
registerForm: FormGroup;
error = '';
@Input() index: number; @Input() index: number;
private ischanged = false; private ischanged = false;
...@@ -18,7 +22,7 @@ export class TextInputViewComponent implements OnInit { ...@@ -18,7 +22,7 @@ export class TextInputViewComponent implements OnInit {
private edit = false; private edit = false;
private discrTemp = ''; private discrTemp = '';
constructor(private data: DataService, private displayC: DisplayComponentService, private inputC: InputComponentService) { } constructor(private formBuilder: FormBuilder, private data: DataService, private displayC: DisplayComponentService, private inputC: InputComponentService) { }
ngOnInit() { ngOnInit() {
if (this.displayC.components[this.index].valid === false) { if (this.displayC.components[this.index].valid === false) {
...@@ -31,10 +35,61 @@ export class TextInputViewComponent implements OnInit { ...@@ -31,10 +35,61 @@ export class TextInputViewComponent implements OnInit {
this.displayC.components[this.index].isDetails = true; this.displayC.components[this.index].isDetails = true;
this.displayC.components[this.index].input = ''; this.displayC.components[this.index].input = '';
this.displayC.components[this.index].placeholder = ''; this.displayC.components[this.index].placeholder = '';
this.displayC.components[this.index].validatorsMin = 5;
this.displayC.components[this.index].validatorsMax = -1;
this.displayC.components[this.index].validatorsReq = true;
this.displayC.components[this.index].validatorsEmail = false;
this.displayC.components[this.index].validatorsIsDigit = false;
this.displayC.components[this.index].validatorsIsAlphabetic = false;
this.displayC.components[this.index].validatorsIsSmall = false;
this.displayC.components[this.index].validatorsIsCapital = false;
this.displayC.components[this.index].validatorsIsAlphaNumeric = false;
this.displayC.components[this.index].validatorsPattern = null;
} else { } else {
this.ischanged = true; this.ischanged = true;
} }
if (this.displayC.components[this.index].validatorsMin >= 0) {
console.log('--1--');
this.error += ('This field should have minimum length of ' + this.displayC.components[this.index].validatorsMin + '\n');
}
if (this.displayC.components[this.index].validatorsMax >= 0) {
console.log('--2--');
this.error += ('This field should have maximum length of ' + this.displayC.components[this.index].validatorsMax + '\n');
}
if (this.displayC.components[this.index].validatorsReq) {
console.log('--3--');
this.error += ('This field is compulsory \n');
}
if (this.displayC.components[this.index].validatorsEmail) {
console.log('--4--');
this.error += ('Input valid email \n');
}
if (this.displayC.components[this.index].validatorsIsAlphaNumeric) {
console.log('--5--');
this.error += ('Only alphanumerics are allowed \n');
}
if (this.displayC.components[this.index].validatorsIsDigit) {
console.log('--6--');
this.error += ('Only digits are allowed \n');
}
if (this.displayC.components[this.index].validatorsIsAlphabetic) {
console.log('--7--');
this.error += ('Only alphabets are allowed \n');
}
if (this.displayC.components[this.index].validatorsIsSmall) {
console.log('--8--');
this.error += ('Only lowercase alphabets are allowed \n');
}
if (this.displayC.components[this.index].validatorsIsCapital) {
console.log('--9--');
this.error += ('Only uppercase alphabets are allowed \n');
}
if (this.displayC.components[this.index].validatorsPattern) {
console.log('--10--');
this.error += ('Make sure you enter valid pattern ' + this.displayC.components[this.index].validatorsPattern + '\n');
}
console.log('length : ' + (this.displayC.components[this.index].title.trim().length < 1)); console.log('length : ' + (this.displayC.components[this.index].title.trim().length < 1));
if (this.displayC.components[this.index].title.trim().length < 1) { if (this.displayC.components[this.index].title.trim().length < 1) {
this.discrTemp = 'Click to add header'; this.discrTemp = 'Click to add header';
...@@ -43,7 +98,59 @@ export class TextInputViewComponent implements OnInit { ...@@ -43,7 +98,59 @@ export class TextInputViewComponent implements OnInit {
this.discrTemp = this.displayC.components[this.index].title.replace(new RegExp('\n', 'g'), '<br />'); this.discrTemp = this.displayC.components[this.index].title.replace(new RegExp('\n', 'g'), '<br />');
} }
this.displayC.components[this.index].valid = true; this.displayC.components[this.index].valid = true;
this.registerForm = this.formBuilder.group({
inputext: ['',
Validators.compose([
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsMin >= 0,
Validators.minLength(this.displayC.components[this.index].validatorsMin)
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsMax >= 0,
Validators.maxLength(this.displayC.components[this.index].validatorsMax)
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsReq === true,
Validators.required
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsEmail === true,
Validators.email
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsIsDigit === true,
Validators.pattern('^[0-9]*$')
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsIsAlphabetic === true,
Validators.pattern('^[a-zA-Z]*$')
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsIsSmall === true,
Validators.pattern('^[a-z]*$')
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsIsCapital === true,
Validators.pattern('^[A-Z]*$')
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsIsAlphaNumeric === true,
Validators.pattern('^[a-zA-Z0-9]*$')
),
ExtraValidators.conditional(
group => this.displayC.components[this.index].validatorsPattern !== null
&& this.displayC.components[this.index].validatorsPattern.length > 0,
Validators.pattern(this.displayC.components[this.index].validatorsPattern)
),
])
]
});
} }
get inputext() { return this.registerForm.get('inputext'); }
enterEditMode() { enterEditMode() {
this.edit = true; this.edit = true;
...@@ -69,3 +176,18 @@ export class TextInputViewComponent implements OnInit { ...@@ -69,3 +176,18 @@ export class TextInputViewComponent implements OnInit {
} }
} }
} }
class ExtraValidators {
i = 10; /*!< just a i value */
static conditional(conditional, validator) {
return (control) => {
if (control && control._parent) {
if (conditional(control._parent)) {
return validator(control);
}
}
};
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment