Skip to content

Commit 68cd04b

Browse files
committed
Grumble: working on form edits (#259)
1 parent 1738ca0 commit 68cd04b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libreforms_fastapi/app/templates/update_form.html.jinja

+7-5
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,25 @@ $(document).ready(function() {
5757
// Populate form fields with fetched data
5858
function populateFormData(response) {
5959
const data = response.data;
60+
61+
console.log(data);
62+
6063
for (const key in data) {
6164
const value = data[key];
6265
const field = $(`[name="${key}"]`);
6366
6467
if (Array.isArray(value)) {
6568
// For checkboxes or multi-selects
6669
value.forEach(val => {
67-
const escapedValue = val.replace(/\./g, '\\.');
68-
$(`[name="${key}"]`).filter(`[value="${escapedValue}"]`).prop('checked', true);
70+
$(`[name="${key}"]`).filter(`[value="${val}"]`).prop('checked', true);
6971
});
7072
} else if (typeof value === 'object' && value !== null) {
71-
// Handle objects (though you mentioned these are rare)
73+
// I'm leaving this hear but I don't think we are going to have too many of these
7274
} else {
7375
// Handle strings and numbers
7476
if(field.is(':radio')) {
75-
const escapedValue = value.replace(/\./g, '\\.');
76-
field.filter(`[value="${escapedValue}"]`).prop('checked', true);
77+
// If the field is a radio button, find the one that matches the value and check it
78+
field.filter(`[value="${value}"]`).prop('checked', true);
7779
} else {
7880
// For all other field types, just set the value
7981
field.val(value);

0 commit comments

Comments
 (0)