{"version":3,"file":"submit_inactive_controller-ByUU51ug.js","sources":["../../../app/javascript/controllers/form/submit_inactive_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static targets = [\"submit\", \"input\"]\n static values = {\n enabled: Boolean,\n autofocus: Boolean\n }\n\n initialize() {\n this.onSubmitListener = this.onSubmitListener.bind(this)\n }\n\n connect() {\n if(this.enabledValue) {\n this.activate()\n } else {\n this.deactivate()\n }\n\n if(this.autofocusValue) {\n this.focus(this.element.querySelector('input[data-autofocus]'), {\n moveCursorToEnd: true\n })\n }\n\n this.element.addEventListener(\"submit\", this.onSubmitListener)\n super.connect()\n }\n\n disconnect() {\n this.element.removeEventListener(\"submit\", this.onSubmitListener)\n super.disconnect()\n }\n\n activate() {\n if (this.active) return\n\n this.submitTarget.disabled = false\n }\n\n deactivate() {\n if (this.inactive) return\n this.submitTarget.disabled = true\n }\n\n // call this on an input where you would like it to disable the submit button\n // when it becomes empty\n sync(e) {\n const length = e.target.isContentEditable\n ? e.target.innerText.trim().length\n : e.target.value.trim().length\n\n if (length === 0) {\n this.deactivate()\n } else {\n this.activate()\n }\n }\n\n syncInputTargets() {\n if (this.filledInputs && (!this.composeSnapshot || this.composeSnapshot.string.length > 0)) {\n this.activate()\n } else {\n this.deactivate()\n }\n }\n\n syncComposeSnapshot({ detail: composeSnapshot }) {\n this.composeSnapshot = composeSnapshot\n\n if(this.filledInputs && composeSnapshot.string.length > 0 && composeSnapshot.technologies.length > 0) {\n this.activate()\n } else {\n this.deactivate()\n }\n }\n\n onSubmitListener(e) {\n if(this.inactive && e.submitter.getAttribute('data-prevent') === null) {\n e.preventDefault()\n }\n }\n\n get active() {\n return this.submitTarget.disabled === false\n }\n\n get inactive() {\n return this.submitTarget.disabled === true\n }\n\n get filledInputs() {\n return this.inputTargets.every((input) => {\n if(input.isContentEditable) {\n return input.innerText.trim().length > 0\n } else if(input.type === 'checkbox') {\n return input.checked\n } else {\n return input.value.trim().length > 0\n }\n })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