1
0
mirror of https://github.com/2ec0b4/kaamelott-soundboard.git synced 2025-12-08 15:43:24 +00:00

Ajoute un bouton de réinitialisation du champ

This commit is contained in:
Antoine
2016-08-05 12:38:37 +02:00
parent f8c64f41be
commit 6490efeee1
4 changed files with 48 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
<form action="index.html" method="post">
<label for="filter">Filtrer les sons</label>
<input type="text" name="s" value="" id="filter" placeholder="Ex. : Perceval">
<input type="reset" value="Réinitialiser" class="btn-reset invisible">
<input type="submit" name="submit" value="Filtrer" class="btn">
</form>

View File

@@ -10,19 +10,35 @@ define("views/filter", function(require) {
template: SoundsFilterTemplate,
ui: {
searchForm: "form",
searchField: "form input[name='s']"
searchField: "form input[name='s']",
btnReset: ".btn-reset"
},
events: {
"submit @ui.searchForm": "filterSounds",
"keyup @ui.searchField": "filterSounds"
"keyup @ui.searchField": "filterSounds",
"click @ui.btnReset": "resetFilter"
},
initialize: function() {
this.channel = Radio.channel("Sounds");
},
filterSounds: function(e) {
var value = this.$el.find(this.ui.searchField).val();
e.preventDefault();
this.channel.trigger("sounds:filter", $(this.ui.searchField).val());
if( value !== "" ) {
this.$el.find(this.ui.btnReset).removeClass('invisible');
} else {
this.$el.find(this.ui.btnReset).addClass('invisible');
}
this.channel.trigger("sounds:filter", value);
},
resetFilter: function(e) {
e.preventDefault();
this.$el.find(this.ui.searchField).val('');
this.$el.find(this.ui.searchForm).submit();
}
});