<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    $form->get('regionName')->setAttributes([
        'placeholder' => $this->translate('地区名称') . (isset($region) ? '' : $this->translate('，可同时添加多个地区，一行一个'))
    ]);

    $form->get('regionSort')->setAttributes([
        'placeholder' => $this->translate('排序')
    ]);

    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('region',
                ['action' => 'index', 'id' =>
                    (isset($this->regionTopInfo) ? $this->regionTopInfo->getRegionId() : (isset($region) ? $region->getRegionTopId() : 0))
                ]);?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?=$this->translate('返回地区列表')?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?=$this->translate('保存地区')?></button>
            <?=(isset($region) ? $this->HelpUrl('regionEdit') : $this->HelpUrl('regionAdd'))?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?=((isset($region) && $region->getRegionId()) ? $this->translate('编辑地区') : $this->translate('添加地区'))?></h3>
                    </div>

                    <div class="box-body">
                        <?=$this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?=$this->translate('地区名称')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-6">
                                <?= $this->formElement($form->get('regionName')); ?>
                                <?= $this->formElementErrors($form->get('regionName'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?=$this->translate('排序')?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?= $this->formElement($form->get('regionSort')); ?>
                                <?= $this->formElementErrors($form->get('regionSort'), ['class'=>'error-message']); ?>
                            </div>
                        </div>

                    </div>

                    <div>
                        <div class="box-footer">
                            <?=$this->formElement($form->get('dberp_csrf')); ?>
                            <?= $this->formElement($form->get('regionTopId')); ?>
                            <button type="submit" class="btn btn-primary col-md-offset-2"><i class="fa fa-check"></i> <?=$this->translate('保存地区')?></button>
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </section>
    <?= $this->form()->closeTag(); ?>

</div>
<script>
    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate({
            rules: {
                regionName: {
                    required: true
                },
                regionSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                regionName: {
                    required: "<?=$this->translate('地区名称不能为空！')?>"
                },
                regionSort: {
                    required: "<?=$this->translate('排序不能为空！')?>",
                    number: "<?=$this->translate('排序必须为数字！')?>",
                    min: "<?=$this->translate('排序最小为1！')?>"
                }
            }
        });
    });
</script>
