gluon-web: simplify DynamicList data attributes, respect size option

This commit is contained in:
Matthias Schiffer 2018-01-30 23:55:08 +01:00
parent bc75ce5c86
commit dbfd22d651
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
3 changed files with 17 additions and 17 deletions

View File

@ -1,11 +1,11 @@
<div<%= <div<%=
attr("data-prefix", id) ..
attr("data-dynlist", { attr("data-dynlist", {
prefix = id,
type = self.datatype, type = self.datatype,
optional = self.datatype and self.optional, optional = self.datatype and self.optional,
}) .. size = self.size,
attr("data-size", self.size) .. placeholder = self.placeholder,
attr("data-placeholder", self.placeholder) })
%>> %>>
<% <%
for i, val in ipairs(self:cfgvalue()) do for i, val in ipairs(self:cfgvalue()) do

File diff suppressed because one or more lines are too long

View File

@ -232,10 +232,8 @@
return obj; return obj;
} }
function init_dynlist(parent, datatype, optional) { function init_dynlist(parent, attr) {
var prefix = parent.getAttribute('data-prefix'); var prefix = attr.prefix;
var holder = parent.getAttribute('data-placeholder');
function dynlist_redraw(focus, add, del) { function dynlist_redraw(focus, add, del) {
var values = []; var values = [];
@ -257,7 +255,7 @@
if (add >= 0) { if (add >= 0) {
focus = add + 1; focus = add + 1;
values.splice(add, 0, ''); values.splice(add, 0, '');
} else if (!optional && values.length == 0) { } else if (!attr.optional && values.length == 0) {
values.push(''); values.push('');
} }
@ -270,13 +268,15 @@
t.index = i; t.index = i;
t.className = 'gluon-input-text'; t.className = 'gluon-input-text';
if (holder) if (attr.size)
t.placeholder = holder; t.size = attr.size;
if (attr.placeholder)
t.placeholder = attr.placeholder;
parent.appendChild(t); parent.appendChild(t);
if (datatype) if (attr.type)
validate_field(t, false, datatype); validate_field(t, false, attr.type);
bind(t, 'keydown', dynlist_keydown); bind(t, 'keydown', dynlist_keydown);
bind(t, 'keypress', dynlist_keypress); bind(t, 'keypress', dynlist_keypress);
@ -292,7 +292,7 @@
t.value = v; t.value = v;
} }
if (optional || values.length > 1) { if (attr.optional || values.length > 1) {
var b = document.createElement('span'); var b = document.createElement('span');
b.className = 'gluon-remove'; b.className = 'gluon-remove';
@ -522,9 +522,9 @@
nodes = document.querySelectorAll('[data-dynlist]'); nodes = document.querySelectorAll('[data-dynlist]');
for (var i = 0, node; (node = nodes[i]) !== undefined; i++) { for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
var list = JSON.parse(node.getAttribute('data-dynlist')); var attr = JSON.parse(node.getAttribute('data-dynlist'));
init_dynlist(node, list.type, list.optional); init_dynlist(node, attr);
} }
update(); update();