Skip to content

Commit 4eb6c68

Browse files
authored
Support date and number fields copy in sample add form (senaite#1897)
* Copy date/time/hidden fields * Changelog
1 parent 6256c38 commit 4eb6c68

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.0.1 (unreleased)
55
------------------
66

7+
- #1897 Support date and number fields copy in sample add form
78
- #1896 Custom date and time widget
89
- #1895 Disable native form validation in header table
910
- #1893 Removed unused field PasswordLifeTime

src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js

+59-2
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,25 @@
11631163
return $(_el).val(value);
11641164
});
11651165
});
1166+
$td1.find("input[type=number]").each(function(index, el) {
1167+
var j, results1;
1168+
console.debug("-> Copy text field");
1169+
$el = $(el);
1170+
value = $el.val();
1171+
return $.each((function() {
1172+
results1 = [];
1173+
for (var j = 1; 1 <= ar_count ? j <= ar_count : j >= ar_count; 1 <= ar_count ? j++ : j--){ results1.push(j); }
1174+
return results1;
1175+
}).apply(this), function(arnum) {
1176+
var _el, _td;
1177+
if (!(arnum > 0)) {
1178+
return;
1179+
}
1180+
_td = $tr.find("td[arnum=" + arnum + "]");
1181+
_el = $(_td).find("input[type=number]")[index];
1182+
return $(_el).val(value);
1183+
});
1184+
});
11661185
$td1.find("textarea").each(function(index, el) {
11671186
var j, results1;
11681187
console.debug("-> Copy textarea field");
@@ -1201,7 +1220,7 @@
12011220
return $(_el).prop("checked", checked);
12021221
});
12031222
});
1204-
$td1.find("input[type='date'],input[type='datetime-local']").each(function(index, el) {
1223+
$td1.find("input[type='date']").each(function(index, el) {
12051224
var j, results1;
12061225
console.debug("-> Copy date field");
12071226
$el = $(el);
@@ -1216,7 +1235,45 @@
12161235
return;
12171236
}
12181237
_td = $tr.find("td[arnum=" + arnum + "]");
1219-
_el = $(_td).find("input[type='date'],input[type='datetime-local']")[index];
1238+
_el = $(_td).find("input[type='date']")[index];
1239+
return $(_el).val(value);
1240+
});
1241+
});
1242+
$td1.find("input[type='time']").each(function(index, el) {
1243+
var j, results1;
1244+
console.debug("-> Copy time field");
1245+
$el = $(el);
1246+
value = $el.val();
1247+
return $.each((function() {
1248+
results1 = [];
1249+
for (var j = 1; 1 <= ar_count ? j <= ar_count : j >= ar_count; 1 <= ar_count ? j++ : j--){ results1.push(j); }
1250+
return results1;
1251+
}).apply(this), function(arnum) {
1252+
var _el, _td;
1253+
if (!(arnum > 0)) {
1254+
return;
1255+
}
1256+
_td = $tr.find("td[arnum=" + arnum + "]");
1257+
_el = $(_td).find("input[type='time']")[index];
1258+
return $(_el).val(value);
1259+
});
1260+
});
1261+
$td1.find("input[type='hidden']").each(function(index, el) {
1262+
var j, results1;
1263+
console.debug("-> Copy hidden field");
1264+
$el = $(el);
1265+
value = $el.val();
1266+
return $.each((function() {
1267+
results1 = [];
1268+
for (var j = 1; 1 <= ar_count ? j <= ar_count : j >= ar_count; 1 <= ar_count ? j++ : j--){ results1.push(j); }
1269+
return results1;
1270+
}).apply(this), function(arnum) {
1271+
var _el, _td;
1272+
if (!(arnum > 0)) {
1273+
return;
1274+
}
1275+
_td = $tr.find("td[arnum=" + arnum + "]");
1276+
_el = $(_td).find("input[type='hidden']")[index];
12201277
return $(_el).val(value);
12211278
});
12221279
});

src/senaite/core/browser/static/js/coffee/bika.lims.analysisrequest.add.coffee

+38-2
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,18 @@ class window.AnalysisRequestAdd
11941194
_el = $(_td).find("input[type=text]")[index]
11951195
$(_el).val value
11961196

1197+
# Copy <input type="number"> fields
1198+
$td1.find("input[type=number]").each (index, el) ->
1199+
console.debug "-> Copy text field"
1200+
$el = $(el)
1201+
value = $el.val()
1202+
$.each [1..ar_count], (arnum) ->
1203+
# skip the first column
1204+
return unless arnum > 0
1205+
_td = $tr.find("td[arnum=#{arnum}]")
1206+
_el = $(_td).find("input[type=number]")[index]
1207+
$(_el).val value
1208+
11971209
# Copy <textarea> fields
11981210
$td1.find("textarea").each (index, el) ->
11991211
console.debug "-> Copy textarea field"
@@ -1219,15 +1231,39 @@ class window.AnalysisRequestAdd
12191231
$(_el).prop "checked", checked
12201232

12211233
# Copy <input type="date"> fields
1222-
$td1.find("input[type='date'],input[type='datetime-local']").each (index, el) ->
1234+
$td1.find("input[type='date']").each (index, el) ->
12231235
console.debug "-> Copy date field"
12241236
$el = $(el)
12251237
value = $el.val()
12261238
$.each [1..ar_count], (arnum) ->
12271239
# skip the first column
12281240
return unless arnum > 0
12291241
_td = $tr.find("td[arnum=#{arnum}]")
1230-
_el = $(_td).find("input[type='date'],input[type='datetime-local']")[index]
1242+
_el = $(_td).find("input[type='date']")[index]
1243+
$(_el).val value
1244+
1245+
# Copy <input type="time"> fields
1246+
$td1.find("input[type='time']").each (index, el) ->
1247+
console.debug "-> Copy time field"
1248+
$el = $(el)
1249+
value = $el.val()
1250+
$.each [1..ar_count], (arnum) ->
1251+
# skip the first column
1252+
return unless arnum > 0
1253+
_td = $tr.find("td[arnum=#{arnum}]")
1254+
_el = $(_td).find("input[type='time']")[index]
1255+
$(_el).val value
1256+
1257+
# Copy <input type="hidden"> fields
1258+
$td1.find("input[type='hidden']").each (index, el) ->
1259+
console.debug "-> Copy hidden field"
1260+
$el = $(el)
1261+
value = $el.val()
1262+
$.each [1..ar_count], (arnum) ->
1263+
# skip the first column
1264+
return unless arnum > 0
1265+
_td = $tr.find("td[arnum=#{arnum}]")
1266+
_el = $(_td).find("input[type='hidden']")[index]
12311267
$(_el).val value
12321268

12331269
# trigger form:changed event

0 commit comments

Comments
 (0)