diff --git a/js/components/forms/new_project.js b/js/components/forms/new_project.js index aaa555d5..219f7314 100644 --- a/js/components/forms/new_project.js +++ b/js/components/forms/new_project.js @@ -16,7 +16,8 @@ export default { initialData: { type: Object, default: () => ({}) - } + }, + modalName: String }, data: function () { @@ -40,6 +41,7 @@ export default { errors: [], environments, name, + readyToSubmit: false } }, @@ -85,7 +87,19 @@ export default { return names.every((n, index) => names.indexOf(n) === index) }, - validateAndOpenModal: function (modalName) { + handleSubmit: function (event) { + if (!this.readyToSubmit) { + event.preventDefault() + this.validateAndOpenModal() + } + }, + + handleCancelSubmit: function () { + this.readyToSubmit = false + this.closeModal(this.modalName) + }, + + validateAndOpenModal: function () { let isValid = this.$children.reduce((previous, newVal) => { // display textInput error if it is not valid if (!newVal.showValid) { @@ -99,7 +113,8 @@ export default { isValid = this.errors.length == 0 && isValid if (isValid) { - this.openModal(modalName) + this.readyToSubmit = true + this.openModal(this.modalName) } } } diff --git a/templates/fragments/edit_project_form.html b/templates/fragments/edit_project_form.html index e6b4977e..b442d3f8 100644 --- a/templates/fragments/edit_project_form.html +++ b/templates/fragments/edit_project_form.html @@ -3,13 +3,13 @@ {% from "components/text_input.html" import TextInput %} {% from "components/alert.html" import Alert %} - + {% set new_project = project is not defined %} {% set form_action = url_for('workspaces.create_project', workspace_id=workspace.id) if new_project else url_for('workspaces.edit_project', workspace_id=workspace.id, project_id=project.id) %} {% set action_text = 'Create' if new_project else 'Update' %} {% set title_text = 'Add a new project' if new_project else 'Edit {} project'.format(project.name) %} -
+ {% call Modal(name=modalName, dismissable=False) %}

{{ action_text }} project !{ name }

@@ -23,7 +23,7 @@
- +
{% endcall %} @@ -75,7 +75,7 @@
- +