| 123456789101112131415161718192021222324252627282930313233343536373839 |
- class ProductForm {
- constructor() {
- this.$supplierField = $("#supplier-id");
- this.$typeField = $("#type");
- this.$skuField = $("#sku");
- this.$supplierField.on("change", () => this.autoFillSku());
- this.$typeField.on("change", () => this.autoFillSku());
- this.autoFillSku();
- }
- get isNew() {
- return $("#new").val() === "1";
- }
- autoFillSku() {
- if(this.$skuField.val() && !this.isNew) {
- return;
- }
- $.post("/api/suggest-sku", {
- supplier_id: this.$supplierField.val(),
- product_type: this.$typeField.val(),
- }).then(response => {
- if(response.sku) {
- this.$skuField.val(response.sku);
- }
- }).catch(error => {
- this.$skuField.val("");
- });
- }
- }
- $(() => new ProductForm());
|