# Enable fields for editing

**URL:** <https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 30, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855 "2023-03-30T18:41:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/1 "2023-03-30T18:41:11Z")

</div>

Hello all,

I created a popup view to edit a record's data (from a SQL Server table), and am using text input fields to display the data. I would like to have them disabled by default, and if the user is ready to make changes click an 'Edit' button and enable the fields.

Two part question:  
Is this a good way to go about it?  
If so, I have attempted to use a message handler but the enabled prop doesn't seem to get the message.

```auto
self.props.enabled = payload['Enable']

```

I used 'Enable' as the key name in the button script:

```auto
def runAction(self, event):
	messageType = 'msg_enable'
	bool_enable = 'True'
	payload = {'Enable':bool_enable}
	system.perspective.sendMessage(messageType, payload)

```

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 30, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/2 "2023-03-30T18:49:50Z")

</div>

You're writing a string into the bool\_enable. You need to set it to `True` or `False`.  
~~But also, I didn't think a table had an `enable` prop? Each of the columns do, which is likely what you're after~~

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 30, 2023, 6:53pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/3 "2023-03-30T18:53:34Z")

</div>

```auto
def runAction(self, event):
	messageType = 'msg_enable'
	bool_enable = True # boolean type
	payload = {'Enable':bool_enable}
	system.perspective.sendMessage(messageType, payload)

```

Have you verified the inputs are actually receiving the message? If you haven't verified this, check it. I recommend something like `system.perspective.print("Heard")` as the first line of the message handler. Also, as a common misconception, a lot of users expect message handling to work in the Designer but it does not - Message Handling only truly works in actual session; try you View in a true session if you've been using the Designer to test your content.

I made a note to use boolean `True` instead of string `'True'`, but as long as you're enabling and not disabling the string value should have been interpreted as `True` anyway.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 8:36pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/4 "2023-03-30T20:36:20Z")

</div>

I changed the value to boolean `True`  
Added the print statement to the receiving handler.

attempted to use the preview mode in the Designer to see if the print statement would work - it does not.

Tested the changed code in session, nothing happens.

Or, I could use a view.custom.property, set the value to true on a button click event, and bind the enabled prop to that view.custom.property.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 30, 2023, 8:50pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/5 "2023-03-30T20:50:20Z")

</div>

> [@mdemaris](#):
>
> Tested the changed code in session, nothing happens.

Then something is set up incorrectly - most likely the scope, but it could also be some sort of inconsistency in the names. Verify the message source (Button) and the listeners (Text Fields) are based in the same View (no embedding). If they are, then verify the Message Handler you have configured is `msg_enable`.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 9:09pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/6 "2023-03-30T21:09:39Z")

</div>

Interesting...  
I set the scope to View, which should work as all components are in the same view, nothing embedded. The text fields and buttons are in different containers, however - perhaps that makes a difference.  
After changing the scope to Page, it works as intended.  
Good to know, thanks!

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/7 "2023-03-30T21:10:33Z")

</div>

so, which method do you think would be better? Using the message handler or a custom property?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 30, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/8 "2023-03-30T21:10:36Z")

</div>

No, different containers should not matter. Is there any chance you could supply the JSON file of the View here?

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 9:12pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/9 "2023-03-30T21:12:43Z")

</div>

This is of the view itself:

```auto
{"type":"view","payload":{"view":{"path":"Page/adm/UserEdit_PU","width":800.0,"height":800.0,"params":{"v_UserID":0}}}}

```

This is from the root:

```auto
[
  {
    "type": "ia.container.flex",
    "version": 0,
    "props": {
      "direction": "column"
    },
    "meta": {
      "name": "root"
    },
    "position": {},
    "custom": {},
    "children": [
      {
        "type": "ia.container.flex",
        "version": 0,
        "props": {
          "justify": "space-around",
          "alignItems": "center"
        },
        "meta": {
          "name": "FlexContainer"
        },
        "position": {
          "basis": "90px"
        },
        "custom": {},
        "children": [
          {
            "type": "ia.input.button",
            "version": 0,
            "props": {
              "text": "Edit"
            },
            "meta": {
              "name": "Edit"
            },
            "position": {
              "basis": "106px"
            },
            "custom": {},
            "events": {
              "component": {
                "onActionPerformed": {
                  "type": "script",
                  "scope": "G",
                  "config": {
                    "script": "\tbool_enable = True\n\tself.view.custom.v_Edit=bool_enable"
                  }
                }
              }
            }
          },
          {
            "type": "ia.input.button",
            "version": 0,
            "props": {},
            "meta": {
              "name": "Button_0"
            },
            "position": {
              "basis": "106px"
            },
            "custom": {},
            "events": {
              "component": {
                "onActionPerformed": {
                  "type": "script",
                  "scope": "G",
                  "config": {
                    "script": "\tmessageType = 'msg_enable'\n\tbool_enable = True\n\tpayload = {'Enable':bool_enable}\n\tsystem.perspective.sendMessage(messageType, payload)"
                  }
                }
              }
            }
          },
          {
            "type": "ia.input.button",
            "version": 0,
            "props": {},
            "meta": {
              "name": "Button_1"
            },
            "position": {
              "basis": "106px"
            },
            "custom": {}
          }
        ]
      },
      {
        "type": "ia.container.flex",
        "version": 0,
        "props": {},
        "meta": {
          "name": "FlexContainer_0"
        },
        "position": {
          "basis": "258px"
        },
        "custom": {},
        "children": [
          {
            "type": "ia.container.flex",
            "version": 0,
            "props": {
              "direction": "column"
            },
            "meta": {
              "name": "FlexContainer"
            },
            "position": {
              "basis": "200px"
            },
            "custom": {},
            "children": [
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "First"
                },
                "meta": {
                  "name": "FirstName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Last"
                },
                "meta": {
                  "name": "LastName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "User Name"
                },
                "meta": {
                  "name": "UserName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Email"
                },
                "meta": {
                  "name": "EmailAddress"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Role"
                },
                "meta": {
                  "name": "Role"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              }
            ]
          },
          {
            "type": "ia.container.flex",
            "version": 0,
            "props": {
              "direction": "column"
            },
            "meta": {
              "name": "FlexContainer_0"
            },
            "position": {
              "basis": "200px"
            },
            "custom": {},
            "children": [
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {},
                "meta": {
                  "name": "FirstName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'First Name'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {},
                "meta": {
                  "name": "LastName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Last Name'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {},
                "meta": {
                  "name": "UserName"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.style.backgroundColor": {
                    "binding": {
                      "config": {
                        "expression": "if({view.custom.v_new}=1,\"#FFFFFF\",\"#000000\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'User Name'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {},
                "meta": {
                  "name": "EmailAddress"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Email'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {
                  "enabled": false
                },
                "meta": {
                  "name": "Role"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Email'], \"none\")"
                      },
                      "type": "expr"
                    }
                  }
                }
              }
            ]
          },
          {
            "type": "ia.container.flex",
            "version": 0,
            "props": {
              "direction": "column"
            },
            "meta": {
              "name": "FlexContainer_2"
            },
            "position": {
              "basis": "200px"
            },
            "custom": {},
            "children": [
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Title"
                },
                "meta": {
                  "name": "Title"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Department"
                },
                "meta": {
                  "name": "Department"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.display.label",
                "version": 0,
                "props": {
                  "text": "Notes"
                },
                "meta": {
                  "name": "Notes"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {}
              },
              {
                "type": "ia.input.checkbox",
                "version": 0,
                "props": {
                  "text": "Gone?"
                },
                "meta": {
                  "name": "UserGone"
                },
                "position": {
                  "basis": "36px"
                },
                "custom": {},
                "propConfig": {
                  "props.selected": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Gone'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              }
            ]
          },
          {
            "type": "ia.container.flex",
            "version": 0,
            "props": {
              "direction": "column"
            },
            "meta": {
              "name": "FlexContainer_1"
            },
            "position": {
              "basis": "200px"
            },
            "custom": {},
            "children": [
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {},
                "meta": {
                  "name": "Title"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Title'], \"none\")"
                      },
                      "type": "expr"
                    }
                  },
                  "props.enabled": {
                    "binding": {
                      "type": "property",
                      "config": {
                        "path": "view.custom.v_Edit"
                      }
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {
                  "enabled": false
                },
                "meta": {
                  "name": "Department"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Department'], \"none\")"
                      },
                      "type": "expr"
                    }
                  }
                }
              },
              {
                "type": "ia.input.text-field",
                "version": 0,
                "props": {
                  "enabled": false
                },
                "meta": {
                  "name": "Notes"
                },
                "position": {
                  "basis": "50px"
                },
                "custom": {},
                "propConfig": {
                  "props.text": {
                    "binding": {
                      "config": {
                        "expression": "try({view.custom.userView}[0, 'Notes'], \"none\")"
                      },
                      "type": "expr"
                    }
                  }
                },
                "scripts": {
                  "customMethods": [],
                  "messageHandlers": [
                    {
                      "messageType": "msg_enable",
                      "script": "\t# implement your handler here\n\tself.props.enabled = payload['Enable']",
                      "sessionScope": false,
                      "pageScope": true,
                      "viewScope": false
                    }
                  ],
                  "extensionFunctions": null
                }
              }
            ]
          }
        ]
      },
      {
        "type": "ia.container.flex",
        "version": 0,
        "props": {},
        "meta": {
          "name": "FlexContainer_1"
        },
        "position": {
          "basis": "101px"
        },
        "custom": {}
      }
    ]
  }
]

```

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 9:14pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/10 "2023-03-30T21:14:28Z")

</div>

If you take a look at the notes text field, that is where the message handler resides

The rest of the text fields I bound to the custom.v\_Edit property

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 30, 2023, 9:26pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/11 "2023-03-30T21:26:43Z")

</div>

I should have been more clear: I was hoping for the View in its non-working state. I'll modify it to be in the state I _believe_ you were in and see what happens.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 30, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/12 "2023-03-30T21:29:25Z")

</div>

When I set the sendMessage invocation to use a scope of "view" and I set the message handler to listen at the View scope it works as it should. I suspect you were allowing for sendMessage to use the default scope which is "page", but without the View being in the non-working state I can only guess that's what it was..

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 30, 2023, 9:36pm UTC](https://forum.inductiveautomation.com/t/enable-fields-for-editing/71855/13 "2023-03-30T21:36:51Z")

</div>

A default of Page scope... yep, that is probably the issue I had. Thanks again!
