X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/4f5cf4e5cdd485de426573c797ae54a7828999fd..025e57806e5c68ec46f3f87474d9e49959f2be9a:/writer.plp diff --git a/writer.plp b/writer.plp index cf19db4..3f9ed98 100644 --- a/writer.plp +++ b/writer.plp @@ -31,6 +31,7 @@ form > ul > li > label + * { width: 40em; } +.multiinput, input,select { box-sizing: border-box; flex-grow: 1; @@ -153,12 +154,18 @@ if (exists $get{copy}) { $row = {%{$row}{ qw(prio lang cat) }}; } elsif ($ENV{REQUEST_METHOD} eq 'POST') {{ + sub parseinput { + return if not length $_[0]; + require Encode; + return Encode::decode_utf8($_[0]); + } + my $replace = $row; - $row = {%post{keys %wordcol}}; - $row->{$_} = [grep {length} @{ $post{"\@$_"} }] for grep { - ref $wordcol{$_} eq 'HASH' and $wordcol{$_}->{-multiple} - } keys %wordcol; - $_ = length ? $_ : undef for values %{$row}; + $row = {map { $_ => + ref $wordcol{$_} eq 'HASH' && $wordcol{$_}->{-multiple} ? + [ map { parseinput($_) } $post{'@'.$_}->@* ] : + scalar parseinput($post{$_}) + } keys %wordcol}; if (!$row->{form}) { if ($row->{ref} ne 'delete') { @@ -190,8 +197,8 @@ elsif ($ENV{REQUEST_METHOD} eq 'POST') {{ $db->insert(word => { ref => $row->{id}, lang => $lang, - form => $val, - }); + form => $_, + }) for parseinput($val); delete $fields{$field}; } return 1; @@ -299,18 +306,19 @@ package Shiar_Sheet::FormRow { ); } else { + my $multiple = ref $val eq 'ARRAY' || $attr->{-multiple}; return ( (map { sprintf('', $col, $_) } $attr->{-label} // ()), - ref $val ne 'ARRAY' ? () : '', + $multiple ? '' : (), (map { sprintf('', $col, EscapeHTML($_)) } ref $val eq 'ARRAY' ? @{$val} : ()), sprintf('', - $col, ref $val eq 'ARRAY' ? '' : EscapeHTML($val), $html + $col, $multiple ? '' : EscapeHTML($val), $html ), - ref $val ne 'ARRAY' ? () : '', + $multiple ? '' : (), (map { sprintf '%s', $col, $_, $row->{form}, $col eq 'source' ? ' hidden' : '';