dev: web: cleanup: more explicit globals; and match inputs more carefully [#2215]
(Don't match the hidden duplicate inputs created by typeahead.js)
This commit is contained in:
parent
e77f733b30
commit
896a20ad98
@ -163,8 +163,8 @@ function addformReset(showmsg) {
|
||||
// Set the add-new-row-on-keypress handler on the add form's current last amount field, only.
|
||||
// (NB: removes all other keypress handlers from all amount fields).
|
||||
function addformLastAmountBindKey() {
|
||||
$('.amount-input').off('keypress');
|
||||
$('.amount-input:last').keypress(addformAddPosting);
|
||||
$('input[name=amount]').off('keypress');
|
||||
$('input[name=amount]:last').keypress(addformAddPosting);
|
||||
}
|
||||
|
||||
// Pre-fill today's date and focus the description field in the add form.
|
||||
@ -193,8 +193,8 @@ function addformAddPosting() {
|
||||
$('#addform .account-postings').append( $('#addform .account-group:last').clone().addClass('added-row') );
|
||||
// renumber and clear the new last account and amount fields
|
||||
var n = $('#addform .account-group').length;
|
||||
$('.account-input:last').prop('placeholder', 'Account '+n).val('');
|
||||
$('.amount-input:last').prop('placeholder','Amount '+n).val(''); // XXX Enable typehead on dynamically created inputs
|
||||
$('input[name=account]:last').prop('placeholder', 'Account '+n).val('');
|
||||
$('input[name=amount]:last' ).prop('placeholder', 'Amount ' +n).val(''); // XXX Enable typehead on dynamically created inputs
|
||||
// and move the keypress handler to the new last amount field
|
||||
addformLastAmountBindKey();
|
||||
}
|
||||
|
||||
@ -1,23 +1,28 @@
|
||||
<script>
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
descriptionsSuggester = new Bloodhound({
|
||||
|
||||
// Set up global completers which can be attached to appropriate inputs when needed
|
||||
|
||||
globalThis.descriptionsCompleter = new Bloodhound({
|
||||
local:#{toBloodhoundJson (toList descriptions)},
|
||||
limit:100,
|
||||
datumTokenizer: function(d) { return [d.value]; },
|
||||
queryTokenizer: function(q) { return [q]; }
|
||||
});
|
||||
descriptionsSuggester.initialize();
|
||||
globalThis.descriptionsCompleter.initialize();
|
||||
|
||||
accountsSuggester = new Bloodhound({
|
||||
globalThis.accountsCompleter = new Bloodhound({
|
||||
local:#{toBloodhoundJson (journalAccountNamesDeclaredOrImplied j)},
|
||||
limit:100,
|
||||
datumTokenizer: function(d) { return [d.value]; },
|
||||
queryTokenizer: function(q) { return [q]; }
|
||||
});
|
||||
accountsSuggester.initialize();
|
||||
globalThis.accountsCompleter.initialize();
|
||||
|
||||
jQuery('input[name=description]').typeahead({ highlight: true }, { source: descriptionsSuggester.ttAdapter() });
|
||||
jQuery('input[name=account]').typeahead({ highlight: true }, { source: accountsSuggester.ttAdapter() });
|
||||
// Attach the completers to the initial form inputs.
|
||||
jQuery('input[name=description]').typeahead({ highlight: true }, { source: globalThis.descriptionsCompleter.ttAdapter() });
|
||||
jQuery('input[name=account]' ).typeahead({ highlight: true }, { source: globalThis.accountsCompleter.ttAdapter() });
|
||||
});
|
||||
|
||||
const utf8textdecoder = new TextDecoder();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user