如何使用Angular和Bootstrap将表单字段分成两列。

huangapple go评论76阅读模式
英文:

how to make the total form fields into two column using Angular and bootstrap

问题

以下是您提供的代码的翻译:

我在Bootstrap模态框中有一个Angular表单,我希望所有字段都分成两列,但根据我的代码,它没有生成预期的输出。我将解释我的代码如下。

<div id="myCouponModal" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <div class="icon-box">
                    <i class="material-icons">&#xE5CD;</i>
                </div>				
                <h4 class="modal-title">优惠券</h4>	
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <!-- div starts -->
                        <form class="form-inline" role="form">
                            <div>
                                <div class="section">
                                    <div class="help-content">
                                        <h5>优惠码:HOLI123</h5>
                                    </div>
                                    <div class="form-content">
                                        <div class="form-field">
                                            <mat-form-field appearance="outline">
                                                <mat-label>规则名称</mat-label>
                                                <input matInput placeholder="规则名称" #RuleName required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券代码</mat-label>
                                                <input matInput placeholder="优惠券代码" 
                                                #CouponCode maxlength="30" pattern="[a-zA-Z0-9]+" (keyup)="makeCaps($event)" required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券类别</mat-label>
                                                <select matNativeControl required (change)="getItemsAsPerCategory($event)"  #CouponCategory>
                                                    <option value="">选择优惠券类别</option>
                                                    <option value=Product>产品</option>
                                                    <option value=Store>商店</option>
                                                    <!-- <option value=Category>类别</option> -->
                                                </select>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券价值</mat-label>
                                                <input matInput placeholder="优惠券价值" 
                                                #CouponValue maxlength="15" pattern="[0-9]+" required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>开始日期</mat-label>
                                                <input matInput [matDatepicker]="picker" placeholder="mm/dd/yyyy" readonly>
                                                <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
                                                <mat-datepicker #picker></mat-datepicker>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>最低购物车价值</mat-label>
                                                <input matInput placeholder="最低购物车价值"  
                                                #maxDisValue maxlength="15" pattern="[0-9]+" required>
                                            </mat-form-field>
                                        </div>
                    
                                        <div class="form-field">
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券类型</mat-label>
                                                <select matNativeControl required  #Type>
                                                    <option value="">选择优惠券类型</option>
                                                    <option value=Flat>固定金额</option>
                                                    <option value=percentage>百分比</option>
                                                </select>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券数量</mat-label>
                                                <input matInput placeholder="优惠券数量" 
                                                #Count maxlength="15" pattern="[0-9]+" required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>优惠券描述</mat-label>
                                                <input matInput placeholder="优惠券描述" #CouponDescription required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>最大折扣值</mat-label>
                                                <input matInput placeholder="最大折扣值" 
                                                #maxDisValue maxlength="15" pattern="[0-9]+" required>
                                            </mat-form-field>
                                            <mat-form-field appearance="outline">
                                                <mat-label>结束日期</mat-label>
                                                <input matInput [matDatepicker]="picker1" placeholder="mm/dd/yyyy" readonly>
                                                <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
                                                <mat-datepicker #picker1></mat-datepicker>
                                            </mat-form-field>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <!-- div starts -->
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-danger" (click)="deleteProductItem()">删除</button>
            </div>
        </div>
    </div>
</div>

在这里,我有一些带有部分标题的字段,根据这个代码,它们都在同一列中显示。我需要将部分标题放在左侧,右侧的所有字段分成两列。

英文:

I have a angular form inside bootstrap modal and i need all the fields will be devided into two columns but as per my code its not generating the output as expected. I am explaining my code below.

&lt;div id=&quot;myCouponModal&quot; class=&quot;modal fade&quot;&gt;
&lt;div class=&quot;modal-dialog modal-lg&quot;&gt;
&lt;div class=&quot;modal-content&quot;&gt;
&lt;div class=&quot;modal-header&quot;&gt;
&lt;div class=&quot;icon-box&quot;&gt;
&lt;i class=&quot;material-icons&quot;&gt;&amp;#xE5CD;&lt;/i&gt;
&lt;/div&gt;				
&lt;h4 class=&quot;modal-title&quot;&gt;Coupons&lt;/h4&gt;	
&lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-body&quot;&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-md-12&quot;&gt;
&lt;!-- div starts --&gt;
&lt;form class=&quot;form-inline&quot; role=&quot;form&quot;&gt;
&lt;div&gt;
&lt;div class=&quot;section&quot;&gt;
&lt;div class=&quot;help-content&quot;&gt;
&lt;h5&gt;Coupon code: HOLI123&lt;/h5&gt;
&lt;/div&gt;
&lt;div class=&quot;form-content&quot;&gt;
&lt;div class=&quot;form-field&quot;&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Rule Name&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Rule Name&quot; #RuleName required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Code&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Coupon Code&quot; 
#CouponCode maxlength=&quot;30&quot; pattern=&quot;[a-zA-Z0-9]+&quot; (keyup)=&quot;makeCaps($event)&quot; required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Category&lt;/mat-label&gt;
&lt;select matNativeControl required (change)=&quot;getItemsAsPerCategory($event)&quot;  #CouponCategory&gt;
&lt;option value=&quot;&quot;&gt;Select Coupon Category&lt;/option&gt;
&lt;option value=Product&gt;Product&lt;/option&gt;
&lt;option value=Store&gt;Store&lt;/option&gt;
&lt;!--&lt;option value=Category&gt;Category&lt;/option&gt; --&gt;
&lt;/select&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Value&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Coupon Value&quot; 
#CouponValue maxlength=&quot;15&quot; pattern=&quot;[0-9]+&quot; required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Start Date&lt;/mat-label&gt;
&lt;input matInput [matDatepicker]=&quot;picker&quot; placeholder=&quot;mm/dd/yyyy&quot; readonly&gt;
&lt;mat-datepicker-toggle matSuffix [for]=&quot;picker&quot;&gt;&lt;/mat-datepicker-toggle&gt;
&lt;mat-datepicker #picker&gt;&lt;/mat-datepicker&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Min Cart Value&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Min Cart Value&quot;  
#maxDisValue maxlength=&quot;15&quot; pattern=&quot;[0-9]+&quot; required&gt;
&lt;/mat-form-field&gt;
&lt;/div&gt;
&lt;div class=&quot;form-field&quot;&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Type&lt;/mat-label&gt;
&lt;select matNativeControl required  #Type&gt;
&lt;option value=&quot;&quot;&gt;Select Coupon Type&lt;/option&gt;
&lt;option value=Flat&gt;Flat&lt;/option&gt;
&lt;option value=percentage&gt;Percentage&lt;/option&gt;
&lt;/select&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Count&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Coupon Count&quot; 
#Count maxlength=&quot;15&quot; pattern=&quot;[0-9]+&quot; required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Coupon Description&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Coupon Description&quot; #CouponDescription required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;Max Discount Value&lt;/mat-label&gt;
&lt;input matInput placeholder=&quot;Max Discount Value&quot; 
#maxDisValue maxlength=&quot;15&quot; pattern=&quot;[0-9]+&quot; required&gt;
&lt;/mat-form-field&gt;
&lt;mat-form-field appearance=&quot;outline&quot;&gt;
&lt;mat-label&gt;End Date&lt;/mat-label&gt;
&lt;input matInput [matDatepicker]=&quot;picker1&quot; placeholder=&quot;mm/dd/yyyy&quot; readonly&gt;
&lt;mat-datepicker-toggle matSuffix [for]=&quot;picker1&quot;&gt;&lt;/mat-datepicker-toggle&gt;
&lt;mat-datepicker #picker1&gt;&lt;/mat-datepicker&gt;
&lt;/mat-form-field&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;!-- div starts --&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-footer&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-info&quot; data-dismiss=&quot;modal&quot;&gt;Cancel&lt;/button&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-danger&quot; (click)=&quot;deleteProductItem()&quot;&gt;Delete&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

Here I have some fields with section header and as per this code its coming like the below image.

如何使用Angular和Bootstrap将表单字段分成两列。

Here all fields are coming in same column. I need the section header should place left and in right section all the fields will be divided into two columns.

答案1

得分: 3

你需要将你的表单分成两列。

 <div class="row">
<div class="col-md-6">
左侧字段
</div>
<div class="col-md-6">
右侧字段
</div>
</div>
英文:

You need to split your form in two columns

 div class = row
div class col-md-6
your left fields
div class col-md-6
your rights fields

huangapple
  • 本文由 发表于 2020年1月3日 17:14:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/59575828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定