<?php

namespace PHPMaker2021\rdigital21;

// Page object
$MataPelajaranEdit = &$Page;
?>
<script>
var currentForm, currentPageID;
var fmata_pelajaranedit;
loadjs.ready("head", function () {
    var $ = jQuery;
    // Form object
    currentPageID = ew.PAGE_ID = "edit";
    fmata_pelajaranedit = currentForm = new ew.Form("fmata_pelajaranedit", "edit");

    // Add fields
    var currentTable = <?= JsonEncode(GetClientVar("tables", "mata_pelajaran")) ?>,
        fields = currentTable.fields;
    if (!ew.vars.tables.mata_pelajaran)
        ew.vars.tables.mata_pelajaran = currentTable;
    fmata_pelajaranedit.addFields([
        ["mapel_id", [fields.mapel_id.visible && fields.mapel_id.required ? ew.Validators.required(fields.mapel_id.caption) : null], fields.mapel_id.isInvalid],
        ["mata_pelajaran", [fields.mata_pelajaran.visible && fields.mata_pelajaran.required ? ew.Validators.required(fields.mata_pelajaran.caption) : null], fields.mata_pelajaran.isInvalid],
        ["kode_mapel", [fields.kode_mapel.visible && fields.kode_mapel.required ? ew.Validators.required(fields.kode_mapel.caption) : null], fields.kode_mapel.isInvalid],
        ["ket", [fields.ket.visible && fields.ket.required ? ew.Validators.required(fields.ket.caption) : null], fields.ket.isInvalid]
    ]);

    // Set invalid fields
    $(function() {
        var f = fmata_pelajaranedit,
            fobj = f.getForm(),
            $fobj = $(fobj),
            $k = $fobj.find("#" + f.formKeyCountName), // Get key_count
            rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1,
            startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
        for (var i = startcnt; i <= rowcnt; i++) {
            var rowIndex = ($k[0]) ? String(i) : "";
            f.setInvalid(rowIndex);
        }
    });

    // Validate form
    fmata_pelajaranedit.validate = function () {
        if (!this.validateRequired)
            return true; // Ignore validation
        var fobj = this.getForm(),
            $fobj = $(fobj);
        if ($fobj.find("#confirm").val() == "confirm")
            return true;
        var addcnt = 0,
            $k = $fobj.find("#" + this.formKeyCountName), // Get key_count
            rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1,
            startcnt = (rowcnt == 0) ? 0 : 1, // Check rowcnt == 0 => Inline-Add
            gridinsert = ["insert", "gridinsert"].includes($fobj.find("#action").val()) && $k[0];
        for (var i = startcnt; i <= rowcnt; i++) {
            var rowIndex = ($k[0]) ? String(i) : "";
            $fobj.data("rowindex", rowIndex);

            // Validate fields
            if (!this.validateFields(rowIndex))
                return false;

            // Call Form_CustomValidate event
            if (!this.customValidate(fobj)) {
                this.focus();
                return false;
            }
        }

        // Process detail forms
        var dfs = $fobj.find("input[name='detailpage']").get();
        for (var i = 0; i < dfs.length; i++) {
            var df = dfs[i],
                val = df.value,
                frm = ew.forms.get(val);
            if (val && frm && !frm.validate())
                return false;
        }
        return true;
    }

    // Form_CustomValidate
    fmata_pelajaranedit.customValidate = function(fobj) { // DO NOT CHANGE THIS LINE!
        // Your custom validation code here, return false if invalid.
        return true;
    }

    // Use JavaScript validation or not
    fmata_pelajaranedit.validateRequired = <?= Config("CLIENT_VALIDATE") ? "true" : "false" ?>;

    // Dynamic selection lists
    fmata_pelajaranedit.lists.ket = <?= $Page->ket->toClientList($Page) ?>;
    loadjs.done("fmata_pelajaranedit");
});
</script>
<script>
loadjs.ready("head", function () {
    // Write your table-specific client script here, no need to add script tags.
});
</script>
<?php $Page->showPageHeader(); ?>
<?php
$Page->showMessage();
?>
<form name="fmata_pelajaranedit" id="fmata_pelajaranedit" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl(false) ?>" method="post">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>
<input type="hidden" name="t" value="mata_pelajaran">
<input type="hidden" name="action" id="action" value="update">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<div class="ew-edit-div"><!-- page* -->
<?php if ($Page->mapel_id->Visible) { // mapel_id ?>
    <div id="r_mapel_id" class="form-group row">
        <label id="elh_mata_pelajaran_mapel_id" class="<?= $Page->LeftColumnClass ?>"><?= $Page->mapel_id->caption() ?><?= $Page->mapel_id->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->mapel_id->cellAttributes() ?>>
<span id="el_mata_pelajaran_mapel_id">
<span<?= $Page->mapel_id->viewAttributes() ?>>
<input type="text" readonly class="form-control-plaintext" value="<?= HtmlEncode(RemoveHtml($Page->mapel_id->getDisplayValue($Page->mapel_id->EditValue))) ?>"></span>
</span>
<input type="hidden" data-table="mata_pelajaran" data-field="x_mapel_id" data-hidden="1" name="x_mapel_id" id="x_mapel_id" value="<?= HtmlEncode($Page->mapel_id->CurrentValue) ?>">
</div></div>
    </div>
<?php } ?>
<?php if ($Page->mata_pelajaran->Visible) { // mata_pelajaran ?>
    <div id="r_mata_pelajaran" class="form-group row">
        <label id="elh_mata_pelajaran_mata_pelajaran" for="x_mata_pelajaran" class="<?= $Page->LeftColumnClass ?>"><?= $Page->mata_pelajaran->caption() ?><?= $Page->mata_pelajaran->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->mata_pelajaran->cellAttributes() ?>>
<span id="el_mata_pelajaran_mata_pelajaran">
<input type="<?= $Page->mata_pelajaran->getInputTextType() ?>" data-table="mata_pelajaran" data-field="x_mata_pelajaran" name="x_mata_pelajaran" id="x_mata_pelajaran" size="30" maxlength="255" value="<?= $Page->mata_pelajaran->EditValue ?>"<?= $Page->mata_pelajaran->editAttributes() ?> aria-describedby="x_mata_pelajaran_help">
<?= $Page->mata_pelajaran->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->mata_pelajaran->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->kode_mapel->Visible) { // kode_mapel ?>
    <div id="r_kode_mapel" class="form-group row">
        <label id="elh_mata_pelajaran_kode_mapel" for="x_kode_mapel" class="<?= $Page->LeftColumnClass ?>"><?= $Page->kode_mapel->caption() ?><?= $Page->kode_mapel->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->kode_mapel->cellAttributes() ?>>
<span id="el_mata_pelajaran_kode_mapel">
<input type="<?= $Page->kode_mapel->getInputTextType() ?>" data-table="mata_pelajaran" data-field="x_kode_mapel" name="x_kode_mapel" id="x_kode_mapel" size="30" maxlength="255" value="<?= $Page->kode_mapel->EditValue ?>"<?= $Page->kode_mapel->editAttributes() ?> aria-describedby="x_kode_mapel_help">
<?= $Page->kode_mapel->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->kode_mapel->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->ket->Visible) { // ket ?>
    <div id="r_ket" class="form-group row">
        <label id="elh_mata_pelajaran_ket" class="<?= $Page->LeftColumnClass ?>"><?= $Page->ket->caption() ?><?= $Page->ket->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->ket->cellAttributes() ?>>
<span id="el_mata_pelajaran_ket">
<template id="tp_x_ket">
    <div class="custom-control custom-radio">
        <input type="radio" class="custom-control-input" data-table="mata_pelajaran" data-field="x_ket" name="x_ket" id="x_ket"<?= $Page->ket->editAttributes() ?>>
        <label class="custom-control-label"></label>
    </div>
</template>
<div id="dsl_x_ket" class="ew-item-list"></div>
<input type="hidden"
    is="selection-list"
    id="x_ket"
    name="x_ket"
    value="<?= HtmlEncode($Page->ket->CurrentValue) ?>"
    data-type="select-one"
    data-template="tp_x_ket"
    data-target="dsl_x_ket"
    data-repeatcolumn="5"
    class="form-control<?= $Page->ket->isInvalidClass() ?>"
    data-table="mata_pelajaran"
    data-field="x_ket"
    data-value-separator="<?= $Page->ket->displayValueSeparatorAttribute() ?>"
    <?= $Page->ket->editAttributes() ?>>
<?= $Page->ket->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->ket->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
</div><!-- /page* -->
<?php if (!$Page->IsModal) { ?>
<div class="form-group row"><!-- buttons .form-group -->
    <div class="<?= $Page->OffsetColumnClass ?>"><!-- buttons offset -->
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit"><?= $Language->phrase("SaveBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
    </div><!-- /buttons offset -->
</div><!-- /buttons .form-group -->
<?php } ?>
</form>
<?php
$Page->showPageFooter();
echo GetDebugMessage();
?>
<script>
// Field event handlers
loadjs.ready("head", function() {
    ew.addEventHandlers("mata_pelajaran");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
