<script type="text/javascript">
    function type () {
        var $this = $("#type");
        var $options = $(".custom-options");
        if ($this.val() === "select") {
            $options.show();
        } else {
            $options.hide();
        }
    }

    $(function () {
        type();

        $("#type").change(function () {
            type();
        });
    })
</script>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3><?= __('Add custom field') ?></h3>
</div>

<form data-ajax action="<?= admin_url_to('/configs/register/add_custom_field') ?>" method="post">
    <?= csrf_field() ?>

    <div class="modal-body">
        <div class="form-group">
            <label class="control-label" for="name"><?= __('Column') ?> <span class="required">*</span></label>
            <select class="form-control" name="name" id="name">
                <option value=""></option>
                <?php foreach (sql_table_columns('MEMB_INFO', config('conn.default.me', config('conn.default.dbname'))) as $column): ?>
                    <option value="<?= $column['COLUMN_NAME'] ?>"><?= $column['COLUMN_NAME'] ?></option>
                <?php endforeach ?>
            </select>
        </div>
		
        <div class="form-group">
            <label class="control-label" for="label"><?= __('Label') ?> <span class="required">*</span></label>
            <input type="text" name="label" class="form-control" id="label" />
        </div>
		
        <div class="form-group">
            <label class="control-label" for="required"><?= __('Required') ?></label>
            <div>
                <input class="form-control toggle" type="checkbox" id="required" value="1" name="required" />
            </div>
        </div>
		
        <div class="form-group">
            <label class="control-label" for="type"><?= __('Type') ?></label>
            <select name="type" class="form-control" id="type">
                <option value="text"><?= __('Text') ?></option>
                <option value="select"><?= __('Select') ?></option>
                <option value="checkbox"><?= __('Checkbox') ?></option>
                <option value="textarea"><?= __('Textarea') ?></option>
            </select>
        </div>
		
        <div class="form-group custom-options">
            <label class="control-label" for="options"><?= __('Options') ?></label>
            <textarea class="form-control" type="text" id="options" name="options"></textarea>
        </div>
    </div>

    <div class="modal-footer" style="margin-top:0">
        <input type="submit" class="btn btn-primary" value="<?= __('Add') ?>" />
    </div>
</form>