parent
70cff26719
commit
69dabab6cc
@ -1,21 +1,38 @@ |
|||||||
import { query } from './table-editor-utils' |
import { query } from './table-editor-utils' |
||||||
|
|
||||||
export default function (dataRoute) { |
export default function (opts) { |
||||||
let $note = $('#field-note') |
let $note = $('#field-note') |
||||||
let lastText = $note.val() |
let $submit = $('#submit-button') |
||||||
|
let $emptyPrompt = $('#empty-note-prompt') |
||||||
|
let lastText = $note.val().trim() |
||||||
|
|
||||||
let handler = _.debounce(function () { |
let handler = _.debounce(function () { |
||||||
query(dataRoute, { |
query(opts.route, { |
||||||
action: 'note.set', |
action: 'note.set', |
||||||
text: lastText |
text: lastText |
||||||
}) |
}) |
||||||
}, 350) |
}, 350) |
||||||
|
|
||||||
$note.on('input', () => { |
$note.on('input', () => { |
||||||
let text = $note.val() |
let text = $note.val().trim() |
||||||
if (text !== lastText) { |
if (text !== lastText) { |
||||||
lastText = text |
lastText = text |
||||||
handler() |
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() |
||||||
} |
} |
||||||
}) |
}) |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue