datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
datatable.directory/resources/assets/js/components/DraftNotePage.js

38 lines
867 B

import { query } from './table-editor-utils'
export default function (opts) {
let $note = $('#field-note')
let $submit = $('#submit-button')
let $emptyPrompt = $('#empty-note-prompt')
let lastText = $note.val().trim()
let handler = _.debounce(function () {
query(opts.route, {
action: 'note.set',
text: lastText
})
}, 350)
$note.on('input', () => {
let text = $note.val().trim()
if (text !== lastText) {
lastText = text
handler()
let empty = text.length === 0
if (opts.anyChanges) {
$submit.toggleClass('disabled', empty)
}
// Hide prompt text if anything is written
$emptyPrompt.toggleClass('hidden', !empty)
}
})
// prevent submit with empty note
$submit.on('click', (e) => {
if ($note.val().trim().length === 0) {
e.preventDefault()
}
})
}