【问题标题】:How to hide/remove default Submit button generated in json schema form Angular 2如何隐藏/删除在json模式表单Angular 2中生成的默认提交按钮
【发布时间】:2018-07-23 18:53:02
【问题描述】:

Image of Issue(更新和取消都是正确的,不需要提交按钮) 我正在尝试在不生成默认提交按钮的情况下生成 json 模式表单。该按钮未在架构或 html 中引用,但仍会生成。我得到的最接近的是在架构中使用 "options": false ,这会导致暂时删除按钮的错误。 有谁知道如何解决这个问题?

{
  "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" }


  ]
} 
<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>

【问题讨论】:

  • 这取决于两个变量的输入类型。如果两个变量(configPath && 文件)都填充了值,按钮将被启用。
  • 更新按钮不是问题,它是由导致问题的 json 模式表单自动生成的提交按钮
  • 查看link,它让您全面了解如何使用此节点模块。
  • 谢谢,我查看此页面已有一段时间了,但似乎无法确定提交按钮生成的确切位置。
  • Cool..Upvote 建议,以便其他人也能从中受益..谢谢

标签: html json angular typescript schema


【解决方案1】:

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

你的.component.html:

<json-schema-form
[schema]="yourJsonSchema"
[layout]="yourJsonFormLayout"
[(data)]="yourData"
[widgets]="yourWidgets"
...
>
</json-schema-form>

你的.component.ts:

...

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

...

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

  yourWidgets = {
    submit: NoneComponent,  
  }

...

【讨论】:

  • 有没有想改变提交按钮的值的?
  • 您可以提供一个覆盖提交按钮的小部件实现,或者您可以隐藏提交并在触发表单提交的表单之外提供您自己的控件。
  • 是的,我一直在表单之外,但只是想知道如何更改提交按钮文本。
  • 我已经有大约一年没有使用该框架了,但是如果内存提供了一个包装或继承默认提交按钮的小部件,如果没有提供用于设置的简单 api,则应该这样做直接提交文本。
猜你喜欢
  • 2016-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-22
  • 1970-01-01
  • 1970-01-01
  • 2018-03-17
  • 1970-01-01
相关资源
最近更新 更多