Press "Enter" to skip to content

How to find a control instance with JavaScript

0

In the current article I would like to share a number of ways, how to find a control instance with JavaScript in K2 Smartforms. Please, note, that this is not supported and might now work as expected in different K2 Versions. Moreover, this is not something you need on a daily basis, but rather rarely for certain functionality, that is not available out of the box. When you need to inject something and need to set or get the value of a control.

This article involves the usage of JavaScript on the form. If something is not clear, please, read the article How to add JavaScript on Smartforms.

A bit of information about a control ID

Uniqueness of a control object is secured via their IDs. Usually, the control ID consists of a GUID of the view instance, placed on the form, and a control ID. If the control is placed directly on the form, the first GUID is replaced with 00000000-0000-0000-0000-000000000000.

i.e. ViewInstanceGUID_ControlGUID
Example of a View control ID:
d9b4dcc2-a3a7-48f2-2075-d162e2bbf4a9_9ac1729f-0061-488c-1357-6a97acdc1857
Example of a Form control ID:
00000000-0000-0000-0000-000000000000_cd8608bd-bc0b-e5a3-8ae5-c0c8be4fcb90

However, for certain controls, like e.g. Text Area, additional suffixes are added.

Example of a Text Area ID:
00000000-0000-0000-0000-000000000000_08d08b6e-0503-f328-a6bd-b28e877fc452_TextArea

I am trying to point out, that there is no generic way to get the control object. Therefore, below I am giving some cases, which are the most frequent.

Finding most of the controls

The first way is suitable for the controls, that have a name attribute in Html. These are the following controls:

  • Label
  • Content
  • Autocomplete
  • Data Label
  • Choice
  • List Box
  • Multi-Select
  • Rich Text
  • Slider
  • Text Box
  • Button

The next approach is suitable for controls, that do not have the Name property in Html.

Picture

Calendar

Check Box

Check Box List & Radio Button List

Drop-Down List

Lookup

Picker

Radio Button

Text Area

Toolbar Button

These are the most frequent types of controls, that users try to find in K2. After you were able to find a control with JavaScript, you can now get and set values or do something else. I will describe that in one of the next posts.

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen + seven =