feat: add form validation for inovasi, lingkungan, and pendidikan modules
- Added isFormValid() and isHtmlEmpty() helper functions for form validation - Disabled submit buttons when required fields are empty across multiple admin and public pages - Applied consistent validation pattern for creating and editing records - Commented out WhatsApp OTP sending in login route for debugging/testing - Fixed path in NavbarMainMenu tooltip action
This commit is contained in:
@@ -19,6 +19,28 @@ function PengaduanMasyarakat() {
|
||||
const [previewImage, setPreviewImage] = useState<string | null>(null);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
|
||||
// Helper function to check if HTML content is empty
|
||||
const isHtmlEmpty = (html: string) => {
|
||||
// Remove all HTML tags and check if there's any text content
|
||||
const textContent = html.replace(/<[^>]*>/g, '').trim();
|
||||
return textContent === '';
|
||||
};
|
||||
|
||||
// Check if form is valid
|
||||
const isFormValid = () => {
|
||||
return (
|
||||
state.pengaduanMasyarakat.create.form.name?.trim() !== '' &&
|
||||
state.pengaduanMasyarakat.create.form.email?.trim() !== '' &&
|
||||
state.pengaduanMasyarakat.create.form.nomorTelepon?.trim() !== '' &&
|
||||
state.pengaduanMasyarakat.create.form.nik?.trim() !== '' &&
|
||||
state.pengaduanMasyarakat.create.form.judulPengaduan?.trim() !== '' &&
|
||||
state.pengaduanMasyarakat.create.form.lokasiKejadian?.trim() !== '' &&
|
||||
!isHtmlEmpty(state.pengaduanMasyarakat.create.form.deskripsiPengaduan) &&
|
||||
state.pengaduanMasyarakat.create.form.jenisPengaduanId?.trim() !== '' &&
|
||||
file !== null
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// ✅ Panggil load data jenis layanan dari backend
|
||||
if (!state.jenisPengaduan.findMany.data) {
|
||||
@@ -207,7 +229,11 @@ function PengaduanMasyarakat() {
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Button bg={colors['blue-button']} onClick={handleSubmit}>
|
||||
<Button
|
||||
bg={colors['blue-button']}
|
||||
onClick={handleSubmit}
|
||||
disabled={!isFormValid()}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user