<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    if(isset($this->phoneArea) && $this->phoneArea->getAreaId() == 1)$form->get('areaState')->setAttributes(['disabled' => true]);
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('phone-area');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回国际电话区号列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存电话区号信息'); ?></button>
            <?php echo $this->HelpUrl('phoneAreaAdd'); ?>
        </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"><?php echo $this->phoneArea ? $this->translate('编辑国际电话区号') : $this->translate('添加国际电话区号'); ?></h3>
                    </div>

                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('选择地区'); ?><span class="must_add_value">*</span></label>
                            <div class="col-sm-3">
                                <?php echo $this->formElement($form->get('areaCode')); ?>
                                <?php echo $this->formElementErrors($form->get('areaCode'), ['class'=>'error-message']); ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('排序'); ?><span class="must_add_value">*</span></label>
                            <div class="col-sm-2">
                                <?php echo $this->formElement($form->get('areaSort')); ?>
                                <?php echo $this->formElementErrors($form->get('areaSort'), ['class'=>'error-message']); ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('状态'); ?></label>
                            <div class="col-sm-2">
                                <div class="checkbox">
                                    <label>
                                        <?php echo $this->formElement($form->get('areaState')); ?><?php echo $this->translate('启用'); ?>
                                    </label>
                                    <?php echo $this->formElementErrors($form->get('areaState'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                areaCode: {
                    required: true
                },
                areaPhoneCode: {
                    required: true
                },
                areaSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                areaCode: {
                    required: "<?php echo $this->translate('地区不能为空!'); ?>"
                },
                areaPhoneCode: {
                    required: "<?php echo $this->translate('区号不能为空!'); ?>"
                },
                areaSort: {
                    required: "<?php echo $this->translate('排序不能为空!'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字!'); ?>",
                    min: "<?php echo $this->translate('排序最小为1!'); ?>"
                }
            }
        });
    });

    $('.select2').select2();
</script>