المكتبة التقنية ←

Alpine.js وJSON Forms: حالة المتصفح والحفظ

English version

For an expense form with repeated travel lines, Alpine.js can manage row editing while APEX handles server processing. My original example used a modal dialog, a static-content region, and P10LINESJSON to carry dates, descriptions, transport types, and costs.

Keep the browser state synchronized

Inside an Alpine component, watch its rows and serialize them to the APEX item:

this.$watch('rows', value => {
  apex.item('P10_LINES_JSON')
    .setValue(JSON.stringify(value));
});

Alpine's watcher already observes nested changes; the original extra { deep: true } option is unnecessary. Alpine: $watch.

Editorial correction: updating a hidden item does not save business data or automatically update server session state. Submit it with the page or explicitly send it through an AJAX request, then run an authorized persistence process. Display “saved” only after that process succeeds. APEX: item API.

Validate before persistence

JSON_TABLE can project submitted JSON into relational columns. Select deliberate error handling; parsing does not replace checks for required fields, valid dates, permitted transport values, nonnegative costs, and payload size. Recalculate authoritative totals on the server. Oracle: JSON_TABLE.

Verify request ownership and every submitted line ID, and detect concurrent changes with a version check. Persist validated changes within the intended transaction.

Further correction: replacing all rows with delete-plus-insert is not a universally safe duplicate-prevention strategy. It can disrupt identities, references, auditing, and concurrent edits. Choose persistence rules for the actual data model.

Interactive Grid remains a valid option. A custom form earns its additional code when the required interaction justifies it.

النسخة العربية

في نموذج مصروفات يحتوي على بنود تنقل متكررة، Alpine.js تقدر تدير تعديل الصفوف، وAPEX تتولى المعالجة على السيرفر. المثال الأصلي استخدم Modal Dialog وStatic Content Region وP10LINESJSON لنقل التاريخ والوصف ونوع التنقل والتكلفة.

زامن حالة المتصفح

داخل Alpine Component، راقب rows وحولها إلى JSON في APEX Item:

this.$watch('rows', value => {
  apex.item('P10_LINES_JSON')
    .setValue(JSON.stringify(value));
});

مراقب Alpine يتابع التغييرات المتداخلة بالفعل؛ خيار { deep: true } الإضافي في الوصف الأصلي غير ضروري. توثيق $watch.

تصحيح تحريري: تغيير Hidden Item لا يحفظ بيانات العمل، ولا يحدث Session State على السيرفر تلقائيًا. أرسل القيمة مع Submit أو بطلب AJAX صريح، ثم نفّذ عملية حفظ تتحقق من الصلاحيات. لا تعرض “تم الحفظ” إلا بعد نجاح العملية. واجهة item في APEX.

تحقق قبل الحفظ

JSON_TABLE تقدر تحول JSON المرسلة إلى أعمدة علائقية. اختار معالجة أخطاء واضحة؛ تحليل JSON لا يغني عن مراجعة الحقول المطلوبة والتواريخ وأنواع التنقل المسموحة وعدم سلبية التكلفة وحجم البيانات. أعد حساب الإجماليات المعتمدة على السيرفر. توثيق JSON_TABLE.

تحقق من ملكية الطلب وكل Line ID مرسلة، واكتشف التعديلات المتزامنة بمراجعة رقم الإصدار. احفظ التغييرات المتحقق منها داخل الـTransaction المقصودة.

تصحيح إضافي: استبدال كل الصفوف بأسلوب Delete ثم Insert ليس طريقة آمنة عامة لمنع التكرار. ممكن يؤثر على المعرّفات والعلاقات وسجل التدقيق والتعديلات المتزامنة. اختار قواعد الحفظ المناسبة لنموذج البيانات الفعلي.

Interactive Grid تظل اختيارًا صالحًا. الفورم المخصصة تستحق الكود الإضافي لما طريقة التفاعل المطلوبة تبرر ذلك.