fix: resolve enum_opsi mismatch and json validation parsing
This commit is contained in:
@@ -37,9 +37,15 @@
|
|||||||
<option value="date">Date</option>
|
<option value="date">Date</option>
|
||||||
<option value="datetime">Datetime</option>
|
<option value="datetime">Datetime</option>
|
||||||
<option value="text">Text</option>
|
<option value="text">Text</option>
|
||||||
<option value="foreign_key">Relasi</option>
|
<option value="enum">Enum</option> <option value="foreign_key">Relasi</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-6 form-control-validation" id="enum-form-opsi-update" style="display: none;">
|
||||||
|
<label class="form-label" for="update-kolom-opsi-enum">Opsi Enum<span class="text-danger">*</span></label>
|
||||||
|
<textarea class="form-control" id="update-kolom-opsi-enum" name="enum_opsi" placeholder='Cth: [{"label": "Ya", "value": "ya"}]'></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mb-6 form-control-validation" id="relasi-form-tabel-update" style="display: none;">
|
<div class="mb-6 form-control-validation" id="relasi-form-tabel-update" style="display: none;">
|
||||||
<label class="form-label" for="update-kolom-relasi-tabel">Tabel Relasi<span class="text-danger">*</span></label>
|
<label class="form-label" for="update-kolom-relasi-tabel">Tabel Relasi<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="update-kolom-relasi-tabel" name="relasi_tabel" placeholder="Cth: Nama Petani" />
|
<input type="text" class="form-control" id="update-kolom-relasi-tabel" name="relasi_tabel" placeholder="Cth: Nama Petani" />
|
||||||
@@ -54,7 +60,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mb-6 form-control-validation">
|
<div class="mb-6 form-control-validation">
|
||||||
<label class="form-label" for="update-kolom-validasi">Validasi<span class="text-danger">*</span></label>
|
<label class="form-label" for="update-kolom-validasi">Validasi<span class="text-danger">*</span></label>
|
||||||
<textarea class="form-control" id="update-kolom-validasi" name="validasi" value="1" placeholder="Cth: required"></textarea>
|
<textarea class="form-control" id="update-kolom-validasi" name="validasi" placeholder="Cth: {"required": true}"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-6 form-control-validation">
|
<div class="mb-6 form-control-validation">
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
@@ -89,17 +95,39 @@
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
|
||||||
$('#update-kolom-jenis_data').select2({
|
$('#update-kolom-jenis_data').select2({
|
||||||
dropdownParent: $('#offcanvasUpdateKolom'),
|
dropdownParent: $('#offcanvasUpdateKolom'),
|
||||||
width: '100%',
|
width: '100%',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#update-kolom-jenis_data').on('change', function() {
|
||||||
|
var tipe = $(this).val();
|
||||||
|
|
||||||
|
|
||||||
|
if (tipe === 'foreign_key') {
|
||||||
|
$('#relasi-form-tabel-update').show();
|
||||||
|
$('#relasi-form-kolom-update').show();
|
||||||
|
$('#relasi-form-kolom-label-update').show();
|
||||||
|
} else {
|
||||||
|
$('#relasi-form-tabel-update').hide();
|
||||||
|
$('#relasi-form-kolom-update').hide();
|
||||||
|
$('#relasi-form-kolom-label-update').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (tipe === 'enum') {
|
||||||
|
$('#enum-form-opsi-update').show();
|
||||||
|
} else {
|
||||||
|
$('#enum-form-opsi-update').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$.validator.addMethod("snakecase", function(value, element) {
|
$.validator.addMethod("snakecase", function(value, element) {
|
||||||
return this.optional(element) || /^[a-z0-9]+(_[a-z0-9]+)*$/.test(value);
|
return this.optional(element) || /^[a-z0-9]+(_[a-z0-9]+)*$/.test(value);
|
||||||
}, "Gunakan format snake_case (huruf kecil dan underscore)");
|
}, "Gunakan format snake_case (huruf kecil dan underscore)");
|
||||||
|
|
||||||
const offcanvasUpdate = new bootstrap.Offcanvas(document.getElementById('offcanvasUpdateKolom'));
|
const offcanvasUpdate = new bootstrap.Offcanvas(document.getElementById('offcanvasUpdateKolom'));
|
||||||
|
|
||||||
$(".edit-record").click(function () {
|
$(".edit-record").click(function () {
|
||||||
const id = $(this).data('id');
|
const id = $(this).data('id');
|
||||||
console.log("Edit record with ID:", id);
|
console.log("Edit record with ID:", id);
|
||||||
@@ -114,21 +142,25 @@
|
|||||||
$('#update-kolom-id').val(res.data.id);
|
$('#update-kolom-id').val(res.data.id);
|
||||||
$('#update-kolom-nama').val(res.data.kolom);
|
$('#update-kolom-nama').val(res.data.kolom);
|
||||||
$('#update-kolom-label').val(res.data.label);
|
$('#update-kolom-label').val(res.data.label);
|
||||||
$('#update-kolom-jenis_data').val(res.data.tipe).trigger('change');
|
|
||||||
$('#update-kolom-validasi').val(res.data.required ? 'required' : '');
|
let validasiVal = (typeof res.data.validasi === 'object' && res.data.validasi !== null)
|
||||||
|
? JSON.stringify(res.data.validasi)
|
||||||
|
: res.data.validasi;
|
||||||
|
$('#update-kolom-validasi').val(validasiVal);
|
||||||
|
|
||||||
|
let opsiEnumVal = (typeof res.data.enum_opsi === 'object' && res.data.enum_opsi !== null)
|
||||||
|
? JSON.stringify(res.data.enum_opsi)
|
||||||
|
: res.data.enum_opsi;
|
||||||
|
$('#update-kolom-opsi-enum').val(opsiEnumVal);
|
||||||
|
|
||||||
if (res.data.tipe === 'foreign_key') {
|
if (res.data.tipe === 'foreign_key') {
|
||||||
console.log("Data relasi:", res.data);
|
|
||||||
$('#update-kolom-relasi-tabel').val(res.data.relasi_tabel);
|
$('#update-kolom-relasi-tabel').val(res.data.relasi_tabel);
|
||||||
$('#update-kolom-relasi-kolom-id').val(res.data.relasi_kolom_id);
|
$('#update-kolom-relasi-kolom-id').val(res.data.relasi_kolom_id);
|
||||||
$('#update-kolom-relasi-kolom-label').val(res.data.relasi_kolom_label);
|
$('#update-kolom-relasi-kolom-label').val(res.data.relasi_kolom_label);
|
||||||
$('#relasi-form-tabel-update').show();
|
|
||||||
$('#relasi-form-kolom-update').show();
|
|
||||||
$('#relasi-form-kolom-label-update').show();
|
|
||||||
} else {
|
|
||||||
$('#relasi-form-tabel-update').hide();
|
|
||||||
$('#relasi-form-kolom-update').hide();
|
|
||||||
$('#relasi-form-kolom-label-update').hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#update-kolom-jenis_data').val(res.data.tipe).trigger('change');
|
||||||
|
|
||||||
$('#update-kolom-is_active').prop('checked', res.data.is_active === 1 || res.data.is_active === true);
|
$('#update-kolom-is_active').prop('checked', res.data.is_active === 1 || res.data.is_active === true);
|
||||||
$('#update-kolom-is_browse').prop('checked', res.data.is_browse === 1 || res.data.is_browse === true);
|
$('#update-kolom-is_browse').prop('checked', res.data.is_browse === 1 || res.data.is_browse === true);
|
||||||
offcanvasUpdate.show();
|
offcanvasUpdate.show();
|
||||||
|
|||||||
Reference in New Issue
Block a user