<?php

namespace PHPMaker2021\gudang_ubi;

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

    // Add fields
    var fields = ew.vars.tables.sup.fields;
    fsupadd.addFields([
        ["sup_nama", [fields.sup_nama.required ? ew.Validators.required(fields.sup_nama.caption) : null], fields.sup_nama.isInvalid],
        ["sup_alamat", [fields.sup_alamat.required ? ew.Validators.required(fields.sup_alamat.caption) : null], fields.sup_alamat.isInvalid],
        ["sup_hp", [fields.sup_hp.required ? ew.Validators.required(fields.sup_hp.caption) : null], fields.sup_hp.isInvalid]
    ]);

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

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

    // Dynamic selection lists
    loadjs.done("fsupadd");
});
</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="fsupadd" id="fsupadd" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl() ?>" 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="sup">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($Page->sup_nama->Visible) { // sup_nama ?>
    <div id="r_sup_nama" class="form-group row">
        <label id="elh_sup_sup_nama" for="x_sup_nama" class="<?= $Page->LeftColumnClass ?>"><?= $Page->sup_nama->caption() ?><?= $Page->sup_nama->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->sup_nama->cellAttributes() ?>>
<span id="el_sup_sup_nama">
<input type="<?= $Page->sup_nama->getInputTextType() ?>" data-table="sup" data-field="x_sup_nama" name="x_sup_nama" id="x_sup_nama" size="30" maxlength="40" placeholder="<?= HtmlEncode($Page->sup_nama->getPlaceHolder()) ?>" value="<?= $Page->sup_nama->EditValue ?>"<?= $Page->sup_nama->editAttributes() ?> aria-describedby="x_sup_nama_help">
<?= $Page->sup_nama->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->sup_nama->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->sup_alamat->Visible) { // sup_alamat ?>
    <div id="r_sup_alamat" class="form-group row">
        <label id="elh_sup_sup_alamat" for="x_sup_alamat" class="<?= $Page->LeftColumnClass ?>"><?= $Page->sup_alamat->caption() ?><?= $Page->sup_alamat->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->sup_alamat->cellAttributes() ?>>
<span id="el_sup_sup_alamat">
<input type="<?= $Page->sup_alamat->getInputTextType() ?>" data-table="sup" data-field="x_sup_alamat" name="x_sup_alamat" id="x_sup_alamat" size="30" maxlength="100" placeholder="<?= HtmlEncode($Page->sup_alamat->getPlaceHolder()) ?>" value="<?= $Page->sup_alamat->EditValue ?>"<?= $Page->sup_alamat->editAttributes() ?> aria-describedby="x_sup_alamat_help">
<?= $Page->sup_alamat->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->sup_alamat->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->sup_hp->Visible) { // sup_hp ?>
    <div id="r_sup_hp" class="form-group row">
        <label id="elh_sup_sup_hp" for="x_sup_hp" class="<?= $Page->LeftColumnClass ?>"><?= $Page->sup_hp->caption() ?><?= $Page->sup_hp->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->sup_hp->cellAttributes() ?>>
<span id="el_sup_sup_hp">
<input type="<?= $Page->sup_hp->getInputTextType() ?>" data-table="sup" data-field="x_sup_hp" name="x_sup_hp" id="x_sup_hp" size="30" maxlength="14" placeholder="<?= HtmlEncode($Page->sup_hp->getPlaceHolder()) ?>" value="<?= $Page->sup_hp->EditValue ?>"<?= $Page->sup_hp->editAttributes() ?> aria-describedby="x_sup_hp_help">
<?= $Page->sup_hp->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->sup_hp->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="<?= 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("sup");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
