<?php

namespace PHPMaker2021\rdigital21;

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

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

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

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

    // Dynamic selection lists
    loadjs.done("fdimensiadd");
});
</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="fdimensiadd" id="fdimensiadd" 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="dimensi">
<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->dimensi->Visible) { // dimensi ?>
    <div id="r_dimensi" class="form-group row">
        <label id="elh_dimensi_dimensi" for="x_dimensi" class="<?= $Page->LeftColumnClass ?>"><?= $Page->dimensi->caption() ?><?= $Page->dimensi->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->dimensi->cellAttributes() ?>>
<span id="el_dimensi_dimensi">
<input type="<?= $Page->dimensi->getInputTextType() ?>" data-table="dimensi" data-field="x_dimensi" name="x_dimensi" id="x_dimensi" size="30" maxlength="255" value="<?= $Page->dimensi->EditValue ?>"<?= $Page->dimensi->editAttributes() ?> aria-describedby="x_dimensi_help">
<?= $Page->dimensi->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->dimensi->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->elemen->Visible) { // elemen ?>
    <div id="r_elemen" class="form-group row">
        <label id="elh_dimensi_elemen" for="x_elemen" class="<?= $Page->LeftColumnClass ?>"><?= $Page->elemen->caption() ?><?= $Page->elemen->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->elemen->cellAttributes() ?>>
<span id="el_dimensi_elemen">
<input type="<?= $Page->elemen->getInputTextType() ?>" data-table="dimensi" data-field="x_elemen" name="x_elemen" id="x_elemen" size="30" maxlength="255" value="<?= $Page->elemen->EditValue ?>"<?= $Page->elemen->editAttributes() ?> aria-describedby="x_elemen_help">
<?= $Page->elemen->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->elemen->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->sub_elemen->Visible) { // sub_elemen ?>
    <div id="r_sub_elemen" class="form-group row">
        <label id="elh_dimensi_sub_elemen" for="x_sub_elemen" class="<?= $Page->LeftColumnClass ?>"><?= $Page->sub_elemen->caption() ?><?= $Page->sub_elemen->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->sub_elemen->cellAttributes() ?>>
<span id="el_dimensi_sub_elemen">
<input type="<?= $Page->sub_elemen->getInputTextType() ?>" data-table="dimensi" data-field="x_sub_elemen" name="x_sub_elemen" id="x_sub_elemen" size="30" maxlength="255" value="<?= $Page->sub_elemen->EditValue ?>"<?= $Page->sub_elemen->editAttributes() ?> aria-describedby="x_sub_elemen_help">
<?= $Page->sub_elemen->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->sub_elemen->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->fase_capaian_d->Visible) { // fase_capaian_d ?>
    <div id="r_fase_capaian_d" class="form-group row">
        <label id="elh_dimensi_fase_capaian_d" for="x_fase_capaian_d" class="<?= $Page->LeftColumnClass ?>"><?= $Page->fase_capaian_d->caption() ?><?= $Page->fase_capaian_d->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->fase_capaian_d->cellAttributes() ?>>
<span id="el_dimensi_fase_capaian_d">
<textarea data-table="dimensi" data-field="x_fase_capaian_d" name="x_fase_capaian_d" id="x_fase_capaian_d" cols="35" rows="4"<?= $Page->fase_capaian_d->editAttributes() ?> aria-describedby="x_fase_capaian_d_help"><?= $Page->fase_capaian_d->EditValue ?></textarea>
<?= $Page->fase_capaian_d->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->fase_capaian_d->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("dimensi");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
