Skip to content

Instantly share code, notes, and snippets.

@webzorg
Created March 11, 2019 19:44
Show Gist options
  • Save webzorg/00b48161a32c77e84973a8aa1260449b to your computer and use it in GitHub Desktop.
Save webzorg/00b48161a32c77e84973a8aa1260449b to your computer and use it in GitHub Desktop.
import { Controller } from "stimulus"
export default class extends Controller {
static targets = ["name", "description", "category", "list"]
postSuccess(event) {
// console.log("ajax: success");
let [data, status, xhr] = event.detail;
this.listTarget.insertAdjacentHTML("afterbegin", xhr.response);
this.nameTarget.value = "";
this.descriptionTarget.value = "";
this.categoryTarget.value = "";
}
postError(event) {
// console.log("ajax: error");
let [data, status, xhr] = event.detail;
data.forEach(function(error_message) {
alertify.error(error_message);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment