Skip to content
Snippets Groups Projects
Commit 5f1db7c6 authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

fix(search) : fix submit search when press enter key

parent 8aaf7497
No related branches found
No related tags found
3 merge requests!14Recette,!13Dev,!6Topic search
...@@ -2,12 +2,19 @@ ...@@ -2,12 +2,19 @@
<span class="title">Acteurs de la médiation</span> <span class="title">Acteurs de la médiation</span>
</div> </div>
<div class="content" fxLayout="column"> <div class="content" fxLayout="column">
<div class="searchSection" fxLayout="row" fxLayoutGap="1.5vw"> <div class="searchSection">
<div class="icon"> <form
<div class="ico-pin-search grey"></div> [formGroup]="searchForm"
</div> fxLayout="row"
<input type="text" [(ngModel)]="searchTerm" placeholder="Rechercher une adresse, une association..." /> fxLayoutGap="1.5vw"
<button type="button" (click)="applyFilter()">Rechercher</button> (ngSubmit)="applyFilter(searchForm.value.searchTerm)"
>
<div class="icon">
<div class="ico-pin-search grey"></div>
</div>
<input type="text" formControlName="searchTerm" placeholder="Rechercher une adresse, une association..." />
<button type="submit">Rechercher</button>
</form>
</div> </div>
<div class="btnSection" fxLayout="row" fxLayoutAlign="space-between center"> <div class="btnSection" fxLayout="row" fxLayoutAlign="space-between center">
...@@ -76,7 +83,7 @@ ...@@ -76,7 +83,7 @@
</div> </div>
<div class="footer" fxLayout="row" fxLayoutAlign="end center" fxLayoutGap="3vw"> <div class="footer" fxLayout="row" fxLayoutAlign="end center" fxLayoutGap="3vw">
<a (click)="clearFilters()">Effacer</a> <a (click)="clearFilters()">Effacer</a>
<button type="button" (click)="applyFilter(modalTypeOpened)">Appliquer</button> <button type="button" (click)="applyFilter(searchForm.value.searchTerm)">Appliquer</button>
</div> </div>
</div> </div>
</div> </div>
......
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { stringToKeyValue } from '@angular/flex-layout/extended/typings/style/style-transforms';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Category } from '../../models/category.model'; import { Category } from '../../models/category.model';
import { Filter } from '../../models/filter.model'; import { Filter } from '../../models/filter.model';
import { Module } from '../../models/module.model'; import { Module } from '../../models/module.model';
...@@ -10,12 +12,16 @@ import { SearchService } from '../../services/search.service'; ...@@ -10,12 +12,16 @@ import { SearchService } from '../../services/search.service';
styleUrls: ['./search.component.scss'], styleUrls: ['./search.component.scss'],
}) })
export class SearchComponent implements OnInit { export class SearchComponent implements OnInit {
constructor(private searchService: SearchService) {} constructor(private searchService: SearchService, private fb: FormBuilder) {
this.searchForm = this.fb.group({
searchTerm: '',
});
}
@Output() searchEvent = new EventEmitter(); @Output() searchEvent = new EventEmitter();
// Search input variable // Form search input
searchTerm: string = ''; searchForm: FormGroup;
// Button variable // Button variable
modalType: string[] = ['accompagnement', 'formations', 'plusFiltres']; modalType: string[] = ['accompagnement', 'formations', 'plusFiltres'];
...@@ -57,14 +63,13 @@ export class SearchComponent implements OnInit { ...@@ -57,14 +63,13 @@ export class SearchComponent implements OnInit {
} }
// Sends an array containing all filters // Sends an array containing all filters
public applyFilter(): void { public applyFilter(term: string): void {
this.checkedModulesFilter = this.checkedModules.slice(); this.checkedModulesFilter = this.checkedModules.slice();
this.openModal(this.modalTypeOpened); this.openModal(this.modalTypeOpened);
// Send search input filter // Send search input filter
let filters: Filter[] = []; let filters: Filter[] = [];
if (this.searchTerm) { if (term) {
filters.push(new Filter('nom', this.searchTerm, false)); filters.push(new Filter('nom', term, false));
} }
// Send checked box filter // Send checked box filter
...@@ -89,9 +94,6 @@ export class SearchComponent implements OnInit { ...@@ -89,9 +94,6 @@ export class SearchComponent implements OnInit {
// Return index of a specific module in array modules // Return index of a specific module in array modules
public getIndex(id: number, categ: string): number { public getIndex(id: number, categ: string): number {
console.log(this.checkedModules);
console.log(id);
console.log(categ);
return this.checkedModules.findIndex((m: Module) => m.id === id && m.text === categ); return this.checkedModules.findIndex((m: Module) => m.id === id && m.text === categ);
} }
......
...@@ -5,11 +5,11 @@ import { CardComponent } from './components/card/card.component'; ...@@ -5,11 +5,11 @@ import { CardComponent } from './components/card/card.component';
import { SearchComponent } from './components/search/search.component'; import { SearchComponent } from './components/search/search.component';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { FlexLayoutModule } from '@angular/flex-layout'; import { FlexLayoutModule } from '@angular/flex-layout';
import { FormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({ @NgModule({
declarations: [StructureListComponent, CardComponent, SearchComponent], declarations: [StructureListComponent, CardComponent, SearchComponent],
imports: [CommonModule, HttpClientModule, FlexLayoutModule, FormsModule], imports: [CommonModule, HttpClientModule, FlexLayoutModule, FormsModule, ReactiveFormsModule],
exports: [StructureListComponent], exports: [StructureListComponent],
}) })
export class StructureListModule {} export class StructureListModule {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment