最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular-Formly: HideDisable Fields from Service - Stack Overflow

programmeradmin0浏览0评论

I have a service in which i try to disable an angular-formly field:

formField.templateOptions.disabled = true;

Even though the templateOption object is correct, the field is not disabled:

"templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test",
    "disabled": true
  },

Is this not possible?

Thanks.

Edit: Form Code before disabling in service

{
  "type": "input",
  "key": "single_line_test",
  "templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test"
  },
  "data": {},
  "validation": {
    "messages": {},
    "errorExistsAndShouldBeVisible": false
  },
  "id": "formly_2_input_single_line_test_3",
  "name": "formly_2_input_single_line_test_3",
  "formControl": {
    "$validators": {},
    "$asyncValidators": {},
    "$parsers": [],
    "$formatters": [
      null
    ],
    "$viewChangeListeners": [],
    "$untouched": true,
    "$touched": false,
    "$pristine": true,
    "$dirty": false,
    "$valid": true,
    "$invalid": false,
    "$error": {},
    "$name": "formly_2_input_single_line_test_3",
    "$options": null
  }
},

I have a service in which i try to disable an angular-formly field:

formField.templateOptions.disabled = true;

Even though the templateOption object is correct, the field is not disabled:

"templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test",
    "disabled": true
  },

Is this not possible?

Thanks.

Edit: Form Code before disabling in service

{
  "type": "input",
  "key": "single_line_test",
  "templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test"
  },
  "data": {},
  "validation": {
    "messages": {},
    "errorExistsAndShouldBeVisible": false
  },
  "id": "formly_2_input_single_line_test_3",
  "name": "formly_2_input_single_line_test_3",
  "formControl": {
    "$validators": {},
    "$asyncValidators": {},
    "$parsers": [],
    "$formatters": [
      null
    ],
    "$viewChangeListeners": [],
    "$untouched": true,
    "$touched": false,
    "$pristine": true,
    "$dirty": false,
    "$valid": true,
    "$invalid": false,
    "$error": {},
    "$name": "formly_2_input_single_line_test_3",
    "$options": null
  }
},
Share Improve this question edited Oct 2, 2015 at 10:42 user2298830 asked Oct 2, 2015 at 9:38 user2298830user2298830 551 gold badge2 silver badges8 bronze badges 1
  • can you post the code for the form too? – Jahongir Rahmonov Commented Oct 2, 2015 at 9:48
Add a ment  | 

1 Answer 1

Reset to default 3

If you want a property to be dynamic, you must use expressionProperties. Technically, you don't have to see it via an expression property, but it needs to be present in expression properties because formly has an optimization that basically says if it's not on there, then it won't watch for changes. This is a performance optimization.

You can see dynamic disabled working in this example: http://angular-formly./#/example/intro/codementor

发布评论

评论列表(0)

  1. 暂无评论