<?php

namespace PHPMaker2021\gudang_ubi;

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

    // Add fields
    var fields = ew.vars.tables.kedatangan.fields;
    fkedatanganadd.addFields([
        ["datang_petugas", [fields.datang_petugas.required ? ew.Validators.required(fields.datang_petugas.caption) : null], fields.datang_petugas.isInvalid],
        ["datang_tanggal", [fields.datang_tanggal.required ? ew.Validators.required(fields.datang_tanggal.caption) : null], fields.datang_tanggal.isInvalid],
        ["datang_varietas", [fields.datang_varietas.required ? ew.Validators.required(fields.datang_varietas.caption) : null], fields.datang_varietas.isInvalid],
        ["datang_jumlah", [fields.datang_jumlah.required ? ew.Validators.required(fields.datang_jumlah.caption) : null], fields.datang_jumlah.isInvalid],
        ["datang_sup", [fields.datang_sup.required ? ew.Validators.required(fields.datang_sup.caption) : null], fields.datang_sup.isInvalid],
        ["datang_catatan", [fields.datang_catatan.required ? ew.Validators.required(fields.datang_catatan.caption) : null], fields.datang_catatan.isInvalid]
    ]);

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

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

    // Dynamic selection lists
    fkedatanganadd.lists.datang_petugas = <?= $Page->datang_petugas->toClientList($Page) ?>;
    fkedatanganadd.lists.datang_varietas = <?= $Page->datang_varietas->toClientList($Page) ?>;
    fkedatanganadd.lists.datang_sup = <?= $Page->datang_sup->toClientList($Page) ?>;
    loadjs.done("fkedatanganadd");
});
</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="fkedatanganadd" id="fkedatanganadd" 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="kedatangan">
<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->datang_tanggal->Visible) { // datang_tanggal ?>
    <div id="r_datang_tanggal" class="form-group row">
        <label id="elh_kedatangan_datang_tanggal" for="x_datang_tanggal" class="<?= $Page->LeftColumnClass ?>"><?= $Page->datang_tanggal->caption() ?><?= $Page->datang_tanggal->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->datang_tanggal->cellAttributes() ?>>
<span id="el_kedatangan_datang_tanggal">
<input type="<?= $Page->datang_tanggal->getInputTextType() ?>" data-table="kedatangan" data-field="x_datang_tanggal" name="x_datang_tanggal" id="x_datang_tanggal" placeholder="<?= HtmlEncode($Page->datang_tanggal->getPlaceHolder()) ?>" value="<?= $Page->datang_tanggal->EditValue ?>"<?= $Page->datang_tanggal->editAttributes() ?> aria-describedby="x_datang_tanggal_help">
<?= $Page->datang_tanggal->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->datang_tanggal->getErrorMessage() ?></div>
<?php if (!$Page->datang_tanggal->ReadOnly && !$Page->datang_tanggal->Disabled && !isset($Page->datang_tanggal->EditAttrs["readonly"]) && !isset($Page->datang_tanggal->EditAttrs["disabled"])) { ?>
<script>
loadjs.ready(["fkedatanganadd", "datetimepicker"], function() {
    ew.createDateTimePicker("fkedatanganadd", "x_datang_tanggal", {"ignoreReadonly":true,"useCurrent":false,"format":0});
});
</script>
<?php } ?>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->datang_varietas->Visible) { // datang_varietas ?>
    <div id="r_datang_varietas" class="form-group row">
        <label id="elh_kedatangan_datang_varietas" for="x_datang_varietas" class="<?= $Page->LeftColumnClass ?>"><?= $Page->datang_varietas->caption() ?><?= $Page->datang_varietas->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->datang_varietas->cellAttributes() ?>>
<span id="el_kedatangan_datang_varietas">
    <select
        id="x_datang_varietas"
        name="x_datang_varietas"
        class="form-control ew-select<?= $Page->datang_varietas->isInvalidClass() ?>"
        data-select2-id="kedatangan_x_datang_varietas"
        data-table="kedatangan"
        data-field="x_datang_varietas"
        data-value-separator="<?= $Page->datang_varietas->displayValueSeparatorAttribute() ?>"
        data-placeholder="<?= HtmlEncode($Page->datang_varietas->getPlaceHolder()) ?>"
        <?= $Page->datang_varietas->editAttributes() ?>>
        <?= $Page->datang_varietas->selectOptionListHtml("x_datang_varietas") ?>
    </select>
    <?= $Page->datang_varietas->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->datang_varietas->getErrorMessage() ?></div>
<?= $Page->datang_varietas->Lookup->getParamTag($Page, "p_x_datang_varietas") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='kedatangan_x_datang_varietas']"),
        options = { name: "x_datang_varietas", selectId: "kedatangan_x_datang_varietas", 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.kedatangan.fields.datang_varietas.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->datang_jumlah->Visible) { // datang_jumlah ?>
    <div id="r_datang_jumlah" class="form-group row">
        <label id="elh_kedatangan_datang_jumlah" for="x_datang_jumlah" class="<?= $Page->LeftColumnClass ?>"><?= $Page->datang_jumlah->caption() ?><?= $Page->datang_jumlah->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->datang_jumlah->cellAttributes() ?>>
<span id="el_kedatangan_datang_jumlah">
<input type="<?= $Page->datang_jumlah->getInputTextType() ?>" data-table="kedatangan" data-field="x_datang_jumlah" name="x_datang_jumlah" id="x_datang_jumlah" size="30" placeholder="<?= HtmlEncode($Page->datang_jumlah->getPlaceHolder()) ?>" value="<?= $Page->datang_jumlah->EditValue ?>"<?= $Page->datang_jumlah->editAttributes() ?> aria-describedby="x_datang_jumlah_help">
<?= $Page->datang_jumlah->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->datang_jumlah->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->datang_sup->Visible) { // datang_sup ?>
    <div id="r_datang_sup" class="form-group row">
        <label id="elh_kedatangan_datang_sup" for="x_datang_sup" class="<?= $Page->LeftColumnClass ?>"><?= $Page->datang_sup->caption() ?><?= $Page->datang_sup->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->datang_sup->cellAttributes() ?>>
<span id="el_kedatangan_datang_sup">
    <select
        id="x_datang_sup"
        name="x_datang_sup"
        class="form-control ew-select<?= $Page->datang_sup->isInvalidClass() ?>"
        data-select2-id="kedatangan_x_datang_sup"
        data-table="kedatangan"
        data-field="x_datang_sup"
        data-value-separator="<?= $Page->datang_sup->displayValueSeparatorAttribute() ?>"
        data-placeholder="<?= HtmlEncode($Page->datang_sup->getPlaceHolder()) ?>"
        <?= $Page->datang_sup->editAttributes() ?>>
        <?= $Page->datang_sup->selectOptionListHtml("x_datang_sup") ?>
    </select>
    <?= $Page->datang_sup->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->datang_sup->getErrorMessage() ?></div>
<?= $Page->datang_sup->Lookup->getParamTag($Page, "p_x_datang_sup") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='kedatangan_x_datang_sup']"),
        options = { name: "x_datang_sup", selectId: "kedatangan_x_datang_sup", 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.kedatangan.fields.datang_sup.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->datang_catatan->Visible) { // datang_catatan ?>
    <div id="r_datang_catatan" class="form-group row">
        <label id="elh_kedatangan_datang_catatan" for="x_datang_catatan" class="<?= $Page->LeftColumnClass ?>"><?= $Page->datang_catatan->caption() ?><?= $Page->datang_catatan->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->datang_catatan->cellAttributes() ?>>
<span id="el_kedatangan_datang_catatan">
<textarea data-table="kedatangan" data-field="x_datang_catatan" name="x_datang_catatan" id="x_datang_catatan" cols="35" rows="4" placeholder="<?= HtmlEncode($Page->datang_catatan->getPlaceHolder()) ?>"<?= $Page->datang_catatan->editAttributes() ?> aria-describedby="x_datang_catatan_help"><?= $Page->datang_catatan->EditValue ?></textarea>
<?= $Page->datang_catatan->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->datang_catatan->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("kedatangan");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
