尝试动态呈现表单时,Nativescript UI rad dataform的行为非常奇怪

时间:2018-04-16 10:00:51

标签: nativescript angular2-nativescript nativescript-telerik-ui

我正在尝试构建一个清单应用程序,其中清单由许多部分组成,每个部分包含许多任务。我使用Nativescript UI-dataform来呈现表单,因为表单是由REST API动态生成的JSON模型。我创建了一个分页器,用于设置当前活动JSON模型的上一个或下一个任务的模板以及数据形式的元数据[源和[元数据输入]。当我点击上一个或下一个V形时,视图会按预期更改,并且数据形式会更新。当我向前移动至少两个任务然后点击left-V形符号(上一个任务页面图标)时,似乎会出现问题。然后表单由于某种原因在文本编辑器中显示任务而不是在元数据模型上显式设置的开关,然后我得到以下错误。我的代码低于错误。知道这里可能出现什么问题/如何解决这个问题?我尝试了其他任何方式都没有取得任何成功,并且当我进行Google搜索时看不到任何相关信息......从错误中看,问题似乎是rad dataform试图使用文本编辑器应该使用布尔开关编辑器吗?

my error:

JS: ERROR Error: java.lang.Error: DataFormTextEditor does not support properties of type Boolean. Please specify a value converter for your property.
JS:     com.telerik.widget.dataform.visualization.core.EntityPropertyViewer.loadPropertyValue(EntityPropertyViewer.java:430)
JS:     com.telerik.widget.dataform.visualization.core.EntityPropertyEditor.loadPropertyValue(EntityPropertyEditor.java:201)
JS:     com.telerik.widget.dataform.visualization.core.EntityPropertyViewer.load(EntityPropertyViewer.java:409)
JS:     com.telerik.widget.dataform.visualization.core.EntityPropertyEditor.load(EntityPropertyEditor.java:189)
JS:     com.telerik.widget.dataform.visualization.RadDataForm.load(RadDataForm.java:806)
JS:     com.telerik.widget.dataform.visualization.RadDataForm.reload(RadDataForm.java:485)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
...


my code:

my xml view code:

<ActionBar title="Dynamic Forms POC" class="action-bar">
</ActionBar>
<StackLayout>
<StackLayout class="m-x-auto m-b-30 p-t-20" orientation="horizontal">
    <Label (tap)="prevTask()" class="font-awesome p-t-4 p-r-10" text="&#xf053;"></Label>
    <Label class="p-b-5" [text]="'Task ' + displayTaskNo() + ' / ' + currentForm.sections[sectionID].tasks.length"></Label>
    <Label (tap)="nextTask()" class="font-awesome p-t-4 p-l-10" text="&#xf054;"></Label>
</StackLayout>

<StackLayout> 
        <RadDataForm #rdf  [source]="currentForm?.sections[sectionID].tasks[taskID].template" [metadata]="currentForm?.sections[sectionID].tasks[taskID].metadata" (propertyCommitted)="onPropertyCommitted()"></RadDataForm>    
    </StackLayout>
</StackLayout>

my prevTask() and nextTask() functions:

prevTask() {
        if (this.taskID === 0) {
            return;
        }

        this.taskID--;        
    }

    nextTask() {
        console.log(this.currentForm.sections[this.sectionID].tasks[this.taskID-1]);
        if (this.taskID === this.currentForm.sections[this.sectionID].tasks.length - 1) {
            return;
        }
        this.taskID++;

    }


a example json model:

{
  "name": "Form1",
  "sections": [
    {
      "secName": "Food Safety Criticals",
      "tasks": [
        {
          "taskName": "Restaurant free of insects / pests",
          "imageNames": [],
          "template": {
            "RestaurantShouldBeFreeOfAllInsectsOrPests": false
          },
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [
              {              
                "name": "RestaurantShouldBeFreeOfAllInsectsOrPests",
                "displayName": "Restaurant should be free of all insects or pests",
                "index": 0,
                "editor":"Switch"
              }
            ]
          }
        },
        {
          "taskName": "only approved ingredients or food evident",
          "imageNames": [],
          "template": {
            "Onlyapprovedingredientsorfoodevident": false
          },          
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [
              {
                "name": "Onlyapprovedingredientsorfoodevident",
                "displayName": "only approved ingredients or food evident",
                "index": 0,
                "editor":"Switch"
              }
            ]
          }        
        },
        {
          "taskName": "Restaurant must have hot water at all times",
          "imageNames": [],
          "template": {
            "Restaurantmusthavehotwateratalltimes": false
          },
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [   
              {
                "name": "Restaurantmusthavehotwateratalltimes",
                "displayName": "Restaurant must have hot water at all times",
                "index": 0,
                "editor": "Switch"
              }
            ]
          }
        },
        {
          "taskName": "Spoiled potentially hazardous foods / ingredients are not in use and not for sale",
          "imageNames": [],
          "template": {
            "Spoiledpotentiallyhazardousfoods/ingredientsarenotinuseandnotforsale": false
          },
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [
              {
                "name": "Spoiledpotentiallyhazardousfoods/ingredientsarenotinuseandnotforsale",
                "displayName": "Spoiled potentially hazardous food / ingredients are not in use and not for sale",
                "index": 0,
                "editor": "Switch"
              }
            ]
          }
        },
        {
          "taskName": "Cross-Contamination is not observed",
          "imageNames": [],
          "template": {
            "Cross-Contaminationisnotobserved": false
          },
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [
              {
                "name": "Cross-Contaminationisnotobserved",
                "displayName": "Cross-Contamination is not observed",
                "index": 0,
                "editor": "Switch"
              }
            ]        
          }
        },
        {
          "taskName": "ColdpotentiallyHazardousFoodsmustbeheld4°Candwithinholdtimesperbrandstandards",
          "imageNames": [],      
          "template": {    
            "ColdpotentiallyHazardousFoodsmustbeheld4°Candwithinholdtimesperbrandstandards": false
          },
          "metadata": {
            "isReadOnly": false,
            "commitMode": "immediate",
            "validationMode": "Immediate",
            "propertyAnnotations": [                     
              {
                "name": "ColdpotentiallyHazardousFoodsmustbeheld4°Candwithinholdtimesperbrandstandards",
                "displayName": "Cold potentially Hazardous Foods must be held 4°C and within hold times per brand standards",
                "index": 0,
                "editor": "Switch"
              }
            ]
          }
        }
      ]  
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

事实证明,当我更改控制器中的“任务”索引时,Rad Dataform获取了表单源的更改,但没有获取元数据的更改... 我为解决这个问题所做的是:每当我导航到上一个/下一个任务时,手动设置表单元数据......