首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何隐藏/删除在json模式表单Angular 2中生成的默认提交按钮

如何隐藏/删除在json模式表单Angular 2中生成的默认提交按钮
EN

Stack Overflow用户
提问于 2018-02-13 19:51:00
回答 1查看 1.7K关注 0票数 0

Image of Issue ( update和cancel是正确的,提交按钮是不需要的)我正在尝试生成一个json模式表单,而不生成默认的提交按钮。该按钮在模式或html中未被引用,但它仍会生成。我得到的最接近的结果是在模式中使用"options":false,这会导致一个错误,该错误会暂时删除按钮。有人知道怎么解决这个问题吗?

代码语言:javascript
复制
{
  "type": "object", 
  "required": [
    "apiName",
    "targetHost",
    "targetPort",
    "numIterations",
    "concurrentUsers",
    "allowablePeakMemoryVariance",
    "allowableServiceResponseTimeVariance",
    "testSuite",
    "requestDelay",
    "TPSFreq",
    "rampUsers",
    "rampDelay",
    "testCaseDir",
    "testSuiteDir",
    "baseStatsOutputDir",
    "reportOutputDir"
  ],
  "properties": {
    "hiddenInput": {
      "type": "boolean",
      "widget": "hidden",
      "default": false,
      "addSubmit": false
    },

    "apiName": { "type": "string" },
    "targetHost": { "type": "string" },
    "targetPort": {
      "type": "string",
      "minimum": 1,
      "maximum": 65535
    },
    "memoryEndpoint": { "type": "string" },
    "numIterations": { "type": "integer", "minimum": 1 },
    "concurrentUsers": { "type": "integer", "minimum": 1 },
    "allowablePeakMemoryVariance": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "allowableServiceResponseTimeVariance": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "testSuite": {
      "type": "string",
      "enum": ["Default-1", "Default-2", "Default-3"]
    },
    "requestDelay": { "type": "integer", "minimum": 1 },
    "TPSFreq": { "type": "integer", "minimum": 1 },
    "rampUsers": { "type": "integer", "minimum": 1 },
    "rampDelay": { "type": "integer", "minimum": 0 },
    "testCaseDir": { "type": "string" },
    "testSuiteDir": { "type": "string" },
    "baseStatsOutputDir": { "type": "string" },
    "reportOutputDir": { "type": "string" }    
  },
  "layout" : [
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "apiName",
        "numIterations",
        {
          "key": "requestDelay",
          "title": "Request Delay (ms)"
        }
      ]
    },
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "targetHost",
        "concurrentUsers",
        {
          "key": "TPSFreq",
          "title": "TPS Frequency (s)"
        }
      ]
    },
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "targetPort",
        {
          "key": "allowablePeakMemoryVariance",
          "title": "Memory Variance (%)"
        },
        "rampUsers"
      ]
    },
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "memoryEndpoint",
        {
          "key": "allowableServiceResponseTimeVariance",
          "title": "Service Variance (%)"
        },
        {
          "key": "rampDelay",
          "title": "Ramp Delay (s)"
        }
      ]
    },
    { "key": "testSuite" },
    { "key": "testCaseDir", "title": "Test Case Directory" },
    { "key": "testSuiteDir", "title": "Test Suites Directory" },
    { "key": "baseStatsOutputDir", "title": "Base Stats Output Directory" },
    { "key": "reportOutputDir", "title": "Report Output Directory" }


  ]
} 
代码语言:javascript
复制
<div class="container">
    <div class="row">
        <div class=" column  col-md-8">
            <label>Config File Path *</label>
            <input class="form-control" type="string" [(ngModel)]="configPath" id="config-file-path" required>

        </div>
        <div class=" column col-md-4">
            <label>File Select</label>
            <input class="form-control" id="xml-file-name" placeholder="Click to Browse Files" [(ngModel)]="xmlFileName" type="string" onclick="javascript:document.getElementById('file').click();">
            <input id="file" type="file" (change)="fileSelector($event)" />

        </div>


    </div>
    <json-schema-form name="auto-generated-fields" ngDefaultControl [schema]="configSchema" ngModel="formData" [layout]="configSchema.layout" framework="bootstrap-4">
    </json-schema-form>
    <button class="btn btn-primary" id="update-config-file-btn" *ngIf="xmlFileName && configPath" (click)="onUpdate(formData)">Update</button>
    <button class="btn btn-primary" id="cancel-btn" (click)="onCancel()">Cancel</button>

</div>
EN

回答 1

Stack Overflow用户

发布于 2018-05-25 06:25:21

如果只想阻止提交按钮呈现,可以覆盖默认的提交按钮小部件。Angular2架构表单包含一个NoneCompnent,它可以提供无操作替换,替换任何您不想显示的内容。

your.component.html:

代码语言:javascript
复制
<json-schema-form
[schema]="yourJsonSchema"
[layout]="yourJsonFormLayout"
[(data)]="yourData"
[widgets]="yourWidgets"
...
>
</json-schema-form>

your.component.ts:

代码语言:javascript
复制
...

import { NoneComponent } from 'angular2-json-schema-form';

...

@Component({
  selector: 'app-your-component',
  templateUrl: './your.component.html',
  ...
})
export class YourComponent {

  yourWidgets = {
    submit: NoneComponent,  
  }

...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48766191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档