<?php

namespace PHPMaker2021\rdigital21;

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

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

    // Set invalid fields
    $(function() {
        var f = ftujuan_pembelajaranadd,
            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
    ftujuan_pembelajaranadd.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
    ftujuan_pembelajaranadd.customValidate = function(fobj) { // DO NOT CHANGE THIS LINE!
        // Your custom validation code here, return false if invalid.
        return true;
    }

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

    // Dynamic selection lists
    ftujuan_pembelajaranadd.lists.kode_mapel = <?= $Page->kode_mapel->toClientList($Page) ?>;
    loadjs.done("ftujuan_pembelajaranadd");
});
</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="ftujuan_pembelajaranadd" id="ftujuan_pembelajaranadd" 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="tujuan_pembelajaran">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($Page->kode_mapel->Visible) { // kode_mapel ?>
    <div id="r_kode_mapel" class="form-group row">
        <label id="elh_tujuan_pembelajaran_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_tujuan_pembelajaran_kode_mapel">
    <select
        id="x_kode_mapel"
        name="x_kode_mapel"
        class="form-control ew-select<?= $Page->kode_mapel->isInvalidClass() ?>"
        data-select2-id="tujuan_pembelajaran_x_kode_mapel"
        data-table="tujuan_pembelajaran"
        data-field="x_kode_mapel"
        data-value-separator="<?= $Page->kode_mapel->displayValueSeparatorAttribute() ?>"
        <?= $Page->kode_mapel->editAttributes() ?>>
        <?= $Page->kode_mapel->selectOptionListHtml("x_kode_mapel") ?>
    </select>
    <?= $Page->kode_mapel->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->kode_mapel->getErrorMessage() ?></div>
<?= $Page->kode_mapel->Lookup->getParamTag($Page, "p_x_kode_mapel") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='tujuan_pembelajaran_x_kode_mapel']"),
        options = { name: "x_kode_mapel", selectId: "tujuan_pembelajaran_x_kode_mapel", language: ew.LANGUAGE_ID, dir: ew.IS_RTL ? "rtl" : "ltr" };
    options.dropdownParent = $(el).closest("#ew-modal-dialog, #ew-add-opt-dialog")[0];
    Object.assign(options, ew.vars.tables.tujuan_pembelajaran.fields.kode_mapel.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->tujuan_pembelajaran->Visible) { // tujuan_pembelajaran ?>
    <div id="r_tujuan_pembelajaran" class="form-group row">
        <label id="elh_tujuan_pembelajaran_tujuan_pembelajaran" for="x_tujuan_pembelajaran" class="<?= $Page->LeftColumnClass ?>"><?= $Page->tujuan_pembelajaran->caption() ?><?= $Page->tujuan_pembelajaran->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->tujuan_pembelajaran->cellAttributes() ?>>
<span id="el_tujuan_pembelajaran_tujuan_pembelajaran">
<textarea data-table="tujuan_pembelajaran" data-field="x_tujuan_pembelajaran" name="x_tujuan_pembelajaran" id="x_tujuan_pembelajaran" cols="35" rows="4"<?= $Page->tujuan_pembelajaran->editAttributes() ?> aria-describedby="x_tujuan_pembelajaran_help"><?= $Page->tujuan_pembelajaran->EditValue ?></textarea>
<?= $Page->tujuan_pembelajaran->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->tujuan_pembelajaran->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("AddBtn") ?></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("tujuan_pembelajaran");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
