From be90f88708e13a246cf5b64188c219ae455489be Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 18 Mar 2025 19:53:56 +0700 Subject: [PATCH] Form builder styling --- system/admin/views/custom-field-page.html.php | 10 ++++---- system/admin/views/custom-field-post.html.php | 10 ++++---- .../admin/views/custom-field-profile.html.php | 10 ++++---- .../admin/views/custom-field-subpage.html.php | 10 ++++---- system/resources/js/form.builder.js | 24 +++++++++++++++---- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/system/admin/views/custom-field-page.html.php b/system/admin/views/custom-field-page.html.php index 59a46da..c7619db 100644 --- a/system/admin/views/custom-field-page.html.php +++ b/system/admin/views/custom-field-page.html.php @@ -12,8 +12,9 @@ if (file_exists($field_file)) {


-
- +
+ +
- + - + No spaces for Name input. Underscores and dashes allowed
diff --git a/system/admin/views/custom-field-post.html.php b/system/admin/views/custom-field-post.html.php index 62bbc14..cff7004 100644 --- a/system/admin/views/custom-field-post.html.php +++ b/system/admin/views/custom-field-post.html.php @@ -12,8 +12,9 @@ if (file_exists($field_file)) {


-
- +
+ +
- + - + No spaces for Name input. Underscores and dashes allowed
diff --git a/system/admin/views/custom-field-profile.html.php b/system/admin/views/custom-field-profile.html.php index 86901a8..92364c6 100644 --- a/system/admin/views/custom-field-profile.html.php +++ b/system/admin/views/custom-field-profile.html.php @@ -12,8 +12,9 @@ if (file_exists($field_file)) {


-
- +
+ +
- + - + No spaces for Name input. Underscores and dashes allowed
diff --git a/system/admin/views/custom-field-subpage.html.php b/system/admin/views/custom-field-subpage.html.php index 380e77f..b75830c 100644 --- a/system/admin/views/custom-field-subpage.html.php +++ b/system/admin/views/custom-field-subpage.html.php @@ -12,8 +12,9 @@ if (file_exists($field_file)) {


-
- +
+ +
- + - + No spaces for Name input. Underscores and dashes allowed
diff --git a/system/resources/js/form.builder.js b/system/resources/js/form.builder.js index e2ca66d..f41cf74 100644 --- a/system/resources/js/form.builder.js +++ b/system/resources/js/form.builder.js @@ -101,6 +101,11 @@ addFieldBtn.addEventListener('click', () => { } updatePreviewAndOutput(); + + document.getElementById(field.name + '-form-preview').scrollIntoView({ + behavior: 'smooth' + }); + }); // Delete field logic @@ -164,6 +169,10 @@ function editField(index) { editingIndex = index; addFieldBtn.textContent = "Update Field"; + document.getElementById('input-status').innerHTML = `
Editing: ${field.label}
`; + document.getElementById('form-input').scrollIntoView({ + behavior: 'smooth' + }); } // Update preview with Edit and Delete buttons @@ -172,7 +181,9 @@ function updatePreviewAndOutput() { fields.forEach((f, index) => { const wrapper = document.createElement('div'); - wrapper.setAttribute('class', 'field-preview form-group'); + wrapper.setAttribute('class', 'field-preview callout callout-info'); + wrapper.setAttribute('id', f.name + '-form-preview'); + formID = f.name; const label = document.createElement('label'); label.innerHTML = `${f.label}
Field ID: ${f.name}`; @@ -215,7 +226,7 @@ function updatePreviewAndOutput() { if (el) { wrapper.appendChild(el); } - + if (f.type === 'checkbox' || f.type === 'select') { const tip = document.createElement('span'); tip.innerHTML = `${f.info}`; @@ -235,6 +246,7 @@ function updatePreviewAndOutput() { wrapper.appendChild(deleteBtn); formPreviewEl.appendChild(wrapper); + }); jsonOutputEl.value = JSON.stringify(fields, null, 2); @@ -246,20 +258,22 @@ function updatePreviewAndOutput() { optionListEl.innerHTML = ''; typeEl.value = "text"; addFieldBtn.textContent = "Add Field"; + document.getElementById('input-status').innerHTML = ''; + } document.addEventListener('DOMContentLoaded', () => { updatePreviewAndOutput(); - + // Real-time removal of spaces in the name field nameEl.addEventListener('input', () => { nameEl.value = nameEl.value.replace(/\s+/g, ''); // Remove spaces in real-time }); - + valueEl.addEventListener('input', () => { if (typeEl.value === 'select') { valueEl.value = valueEl.value.replace(/\s+/g, ''); // Remove spaces } }); - + });