fix #32, could not open attribute dialog if it didn't have any attributes yet

This commit is contained in:
azivner 2018-02-05 21:07:18 -05:00
parent aee64b2522
commit 23a2b58b24
2 changed files with 5 additions and 6 deletions

View File

@ -22,7 +22,8 @@ const attributesDialog = (function() {
attributeNames = await server.get('attributes/names');
$(".attribute-name:last").focus();
// attribute might not be rendered immediatelly so could not focus
setTimeout(() => $(".attribute-name:last").focus(), 100);
};
function isValid() {
@ -65,9 +66,9 @@ const attributesDialog = (function() {
function addLastEmptyRow() {
const attrs = self.attributes();
const last = attrs[attrs.length - 1]();
const last = attrs.length === 0 ? null : attrs[attrs.length - 1]();
if (last.name.trim() !== "" || last.value !== "") {
if (!last || last.name.trim() !== "" || last.value !== "") {
self.attributes.push(ko.observable({
attributeId: '',
name: '',
@ -149,8 +150,6 @@ const attributesDialog = (function() {
$(this).autocomplete("search", $(this).val());
});
$(document).on('blur', '.attribute-name', function (e) { console.log("blur!"); });
$(document).on('focus', '.attribute-value', async function (e) {
if (!$(this).hasClass("ui-autocomplete-input")) {
const attributeName = $(this).parent().parent().find('.attribute-name').val();

View File

@ -389,7 +389,7 @@
<div id="attributes-dialog" title="Note attributes" style="display: none; padding: 20px;">
<form data-bind="submit: save">
<div style="text-align: center">
<button class="btn-primary btn-large" id="save-attributes-button" type="submit">Save</button>
<button class="btn btn-large" style="width: 200px;" id="save-attributes-button" type="submit">Save <kbd>enter</kbd></button>
</div>
<div style="height: 97%; overflow: auto">