diff --git a/assets/controllers/hide_food_controller.js b/assets/controllers/hide_food_controller.js new file mode 100644 index 0000000..d905cda --- /dev/null +++ b/assets/controllers/hide_food_controller.js @@ -0,0 +1,23 @@ +import {Controller} from "@hotwired/stimulus"; + + +export default class extends Controller { + static targets = ['foodSelect', 'ticketSelect']; + + prevValue; + + connect() { + this.hide(); + } + + hide() { + if (this.ticketSelectTarget.value === '2') { + this.foodSelectTarget.disabled = true; + this.prevValue = this.foodSelectTarget.value; + this.foodSelectTarget.value = '0'; + } else { + this.foodSelectTarget.disabled = false; + this.foodSelectTarget.value = this.prevValue ?? ''; + } + } +} \ No newline at end of file diff --git a/templates/ticket/_partials/_form.html.twig b/templates/ticket/_partials/_form.html.twig index 199089f..90ac8c4 100644 --- a/templates/ticket/_partials/_form.html.twig +++ b/templates/ticket/_partials/_form.html.twig @@ -1,13 +1,17 @@