Skip to content

Instantly share code, notes, and snippets.

@iandesj
Created January 5, 2017 05:14
Show Gist options
  • Save iandesj/95346cfb33b2f12d858fdd5202e343e3 to your computer and use it in GitHub Desktop.
Save iandesj/95346cfb33b2f12d858fdd5202e343e3 to your computer and use it in GitHub Desktop.
diff --git a/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.html b/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.html
index 2b40150..3c74b2d 100644
--- a/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.html
+++ b/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.html
@@ -91,7 +91,7 @@
<div class="col-sm-12">
<div class="btn-group pull-right">
<button type="button" class="btn btn-default" (click)="resetForm()">Reset</button>
- <button #btnSubmit [disabled]="pristineInvalid" class="btn btn-primary" (click)="submitSearch(searchForm)">Submit</button>
+ <button #btnSubmit [disabled]="isSubmitDisabled()" class="btn btn-primary" (click)="submitSearch(searchForm)">Submit</button>
</div>
</div>
</form>
@@ -238,7 +238,7 @@
<div class="col-sm-12">
<div class="btn-group pull-right">
<button type="button" class="btn btn-default" (click)="resetForm()">Reset</button>
- <button #btnSubmit [disabled]="pristineInvalid" class="btn btn-primary" (click)="submitSearch(searchForm)">Submit</button>
+ <button #btnSubmit [disabled]="isSubmitDisabled()" class="btn btn-primary" (click)="submitSearch(searchForm)">Submit</button>
</div>
</div>
</form>
diff --git a/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.ts b/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.ts
index aa16452..0bf1a70 100644
--- a/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.ts
+++ b/LOTS/LOTS.Web/app/shared/search/common-search/common-search.component.ts
@@ -113,12 +113,6 @@ export class CommonSearchComponent implements OnInit, AfterViewChecked {
}
public ngAfterViewChecked() {
- if (this.checkPristineInvalid()) {
- this.pristineInvalid = true;
- } else {
- this.pristineInvalid = this.InvalidParcelSearch();
- }
-
this.changeDetectorRef.detectChanges();
}
@@ -380,45 +374,25 @@ export class CommonSearchComponent implements OnInit, AfterViewChecked {
}
}
- private InvalidParcelSearch(): boolean {
- return false;
-
-/*
- let invalidSearch = true;
-
- if (this.searchForm.controls[this.COUNTIES].value &&
- this.searchForm.controls[this.COUNTIES].value.length > 0) {
- invalidSearch = false;
- }
-
- if (this.searchForm.controls[this.JURISDICTION_ID].value !== "") {
- invalidSearch = false;
- }
-
- if (this.searchForm.controls[this.SUBDIVISION_ID].value !== "") {
- invalidSearch = false;
- }
-
- if (this.searchForm.controls[this.PARCELID].value) {
- invalidSearch = false;
- }
-
- if (this.searchForm.controls[this.TOWN].value) {
- invalidSearch = false;
- }
-
- if (this.searchForm.controls[this.SECTION_NUM].value) { invalidSearch = false; }
-
- if (this.searchForm.controls[this.QUARTER].value) {
- invalidSearch = false;
- }
+ private isSubmitDisabled(): boolean {
+ // tslint:disable
+ for (let control in this.searchForm.controls) {
+ let field = this.searchForm.get(control);
+ if (field.value) {
+ if ((field.value.constructor === String || field.value.constructor === Array)
+ && field.value.length > 0 && field.valid) {
+ return false;
+ }
- if (this.searchForm.controls[this.QUARTERQUARTER].value) {
- invalidSearch = false;
+ else if (field.value.constructor === FormGroup
+ && !field.value.pristine && field.value.valid) {
+ return false;
+ } else {
+ return true;
+ }
+ }
}
-
- return invalidSearch;
- */
+ // tslint:enable
}
private assignFormControls(): void {
@@ -441,8 +415,8 @@ export class CommonSearchComponent implements OnInit, AfterViewChecked {
SearchConstants.DOC_DATE,
new FormControl(this.fb.group({ operation: "between",
value: ["", Validators.pattern(this.REGEX_DATE)],
- value2: ["", Validators.pattern(this.REGEX_DATE)] },
- { validator: this.dateValid("operation", "value", "value2") })));
+ value2: ["", Validators.pattern(this.REGEX_DATE)] }),
+ this.dateValid ));
this.searchForm.addControl(SearchConstants.DOC_ID, new FormControl(""));
this.searchForm.addControl(
SearchConstants.DOC_NUM,
@@ -543,20 +517,20 @@ export class CommonSearchComponent implements OnInit, AfterViewChecked {
return search;
}
- private dateValid(operator: string, value: string, value2: string) {
+ private dateValid(control: FormControl) {
let valid = true;
- return (group: FormGroup): {[key: string]: any} => {
- let v = Date.parse(group.controls[value].value);
- let v2 = Date.parse(group.controls[value2].value);
- if (group.controls[operator].value === "between") {
- return {
- dateValid: v < v2,
- };
- } else {
- return {
- dateValid: true,
- };
- }
- };
+ let v = Date.parse(control.value.value[SearchConstants.VALUE].value);
+ let v2 = Date.parse(control.value.value[SearchConstants.VALUE2].value);
+ if (control.value.value[SearchConstants.OPERATION].value === "between") {
+ valid = v < v2;
+ } else {
+ valid = true;
+ }
+ if (valid) {
+ return {
+ dateValid: valid,
+ };
+ }
+ return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment