Skip to main content

Implementation Guide: Reusable In-Place & Modal Editing Components

This guide explains how to implement a powerful set of Vue components for in-place and modal-based editing within a web application. We will cover two primary integration methods:
  1. Laravel Blade Integration: Ideal for traditional server-rendered applications where you want to “sprinkle” interactivity onto a page generated by Laravel.
  2. Full Vue Component: Suitable for Single Page Applications (SPAs) or complex front-end sections where Vue manages the entire state and rendering.

Component Files

This system relies on a set of Vue components. Ensure you have the full code for these files (as provided in previous answers) and they are placed in your resources/js/components/ directory.
  • DynamicFormInputs.vue: The core component that renders different form inputs.
  • InPlaceEdit.vue: The component for inline (in-place) editing.
  • ModalTrigger.vue: The clickable element that opens the editing modal.
  • EditModalContainer.vue: The modal itself, which contains the editing form.

Prerequisites

Before you begin, ensure your project is set up with:
  1. NPM Dependencies: vue, axios, bootstrap-vue, ant-design-vue@^1.7.8, moment.
  2. Event Bus: A simple resources/js/EventBus.js file:
  3. Main JavaScript (resources/js/app.js): Your entry point must be configured to initialize Vue and register the necessary components and plugins.


Part 1: Laravel Blade Integration

This is the recommended approach when your table structure is rendered by a Blade template. Vue will attach to the existing HTML and make it interactive.

Step 1: Prepare Data in Laravel Controller

Your controller should fetch the attendance data and prepare any options needed for select inputs. AttendanceController.php

Step 2: Render the Table in Blade View

In your attendance.blade.php, loop through the data and place the Vue component tags directly in the table cells. resources/views/attendance.blade.php
Key Blade Syntax:
  • :prop="...": The colon binds the prop, evaluating the content as a JavaScript expression. Use it for numbers, booleans, or objects.
  • prop="...": No colon means the prop is passed as a static string.
  • @json($array): The correct and safe way to pass a PHP array to a Vue prop.
  • ?? 'null': A safeguard for numeric props that might be null in the database.

Step 3: Initialize Vue in app.js

Your main JavaScript file boots Vue and registers the components used in the Blade template. resources/js/app.js


Part 2: Full Vue Component Implementation

This approach is used when an entire section of your page, including the table, is managed by Vue. AttendanceTable.vue

[Bahasa Indonesia]

Panduan Implementasi: Komponen Vue Edit In-Place & Modal

Panduan ini menjelaskan cara mengimplementasikan satu set komponen Vue untuk fungsionalitas edit di tempat (in-place) dan berbasis modal. Kami akan membahas dua metode integrasi utama:
  1. Integrasi dengan Laravel Blade: Ideal untuk aplikasi tradisional yang dirender oleh server, di mana Anda ingin menambahkan interaktivitas pada halaman yang dibuat oleh Laravel.
  2. Komponen Vue Penuh: Cocok untuk Single Page Applications (SPA) atau bagian front-end yang kompleks di mana Vue mengelola seluruh state dan proses rendering.

File Komponen

Sistem ini bergantung pada satu set komponen Vue. Pastikan Anda memiliki kode lengkap untuk file-file ini (seperti yang diberikan di jawaban sebelumnya) dan letakkan di direktori resources/js/components/.
  • DynamicFormInputs.vue: Komponen inti yang merender berbagai input form.
  • InPlaceEdit.vue: Komponen untuk edit langsung di tempat (inline).
  • ModalTrigger.vue: Elemen yang dapat diklik untuk membuka modal edit.
  • EditModalContainer.vue: Komponen modal itu sendiri, yang berisi form edit.

Persyaratan

Sebelum memulai, pastikan proyek Anda telah disiapkan dengan:
  1. Dependensi NPM: vue, axios, bootstrap-vue, ant-design-vue@^1.7.8, moment.
  2. Event Bus: File sederhana resources/js/EventBus.js:
  3. JavaScript Utama (resources/js/app.js): File entri Anda harus dikonfigurasi untuk menginisialisasi Vue dan mendaftarkan komponen serta plugin yang diperlukan.


Bagian 1: Integrasi dengan Laravel Blade

Ini adalah pendekatan yang disarankan ketika struktur tabel Anda dirender oleh template Blade. Vue akan “menempel” pada HTML yang ada dan membuatnya interaktif.

Langkah 1: Siapkan Data di Controller Laravel

Controller Anda harus mengambil data kehadiran dan menyiapkan opsi yang diperlukan untuk input select. AttendanceController.php

Langkah 2: Render Tabel di View Blade

Di file attendance.blade.php Anda, lakukan looping data dan letakkan tag komponen Vue langsung di dalam sel tabel. resources/views/attendance.blade.php
Sintaks Penting di Blade:
  • :prop="...": Tanda titik dua (:) melakukan binding pada prop, mengevaluasi isinya sebagai ekspresi JavaScript. Gunakan untuk angka, boolean, atau objek.
  • prop="...": Tanpa titik dua berarti prop dilewatkan sebagai string statis.
  • @json($array): Cara yang benar dan aman untuk melewatkan array PHP ke prop Vue.
  • ?? 'null': Pengaman untuk prop numerik yang mungkin bernilai null di database.

Langkah 3: Inisialisasi Vue di app.js

File JavaScript utama Anda akan mem-boot Vue dan mendaftarkan komponen yang digunakan dalam template Blade. resources/js/app.js


Bagian 2: Implementasi Komponen Vue Penuh

Pendekatan ini digunakan ketika seluruh bagian halaman, termasuk tabel, dikelola oleh Vue. AttendanceTable.vue