Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display alert both before reloading and when pressing the browser back button #144 #146

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Article extends Resource
```

{% hint style="info" %}
This feature has been available since <mark style="color:red;">v7.6.0</mark>
This feature has been available since <mark style="color:red;">v7.7.0</mark>
{% endhint %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if you’d rather disable this behavior, simply set <mark style="color:red;">`to


{% hint style="info" %}
This feature has been available since <mark style="color:red;">v7.6.0</mark>
This feature has been available since <mark style="color:red;">v7.7.0</mark>
{% endhint %}


Expand Down
22 changes: 6 additions & 16 deletions resources/js/fields/editor-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import CkEditor from '../ckeditor/ckeditor'
import SnippetBrowser from "../components/snippet-browser/SnippetBrowser.vue"
import MediaBrowser from '../components/media-browser/MediaBrowser.vue'
import HasUUID from "../components/mixins/hasUUID"
import {DependentFormField, HandlesValidationErrors} from 'laravel-nova'
import {DependentFormField, HandlesValidationErrors, PreventsFormAbandonment} from 'laravel-nova'
import debounce from 'lodash/debounce'
import RegexParser from 'regex-parser'

export default {
mixins: [DependentFormField, HandlesValidationErrors, HasUUID],
mixins: [DependentFormField, HandlesValidationErrors, PreventsFormAbandonment, HasUUID],
props: ['resourceName', 'resourceId', 'field', 'toolbar', 'formUniqueId'],
components: {SnippetBrowser, MediaBrowser},
data() {
Expand Down Expand Up @@ -117,6 +117,10 @@ export default {

model.document.on('change:data', () => {
this.fieldHasChanged = true

if (this.currentField.alertBeforeUnsavedChanges) {
this.preventLeavingForm()
}
})

editor.editing.view.change((writer) => {
Expand Down Expand Up @@ -289,8 +293,6 @@ export default {

fill(formData) {
if (this.currentlyIsVisible) {
this.fieldHasChanged = false

formData.append(this.currentField.attribute, this.value || '')
}
},
Expand Down Expand Up @@ -331,16 +333,6 @@ export default {
resizeObserver.observe(innerEditor[0])
}
},

alertOnUnchangedSaves() {
if (this.currentField.alertBeforeUnsavedChanges) {
window.addEventListener('beforeunload', (event) => {
if (this.fieldHasChanged) {
event.preventDefault()
}
})
}
}
},
created() {
this.$options[this.editorUUID] = this.uuid()
Expand All @@ -353,8 +345,6 @@ export default {
}

this.mounted = true

this.alertOnUnchangedSaves()
},
beforeUnmount() {
this.destroyCkEditor()
Expand Down