Show last authors
1 {{content/}}
2
3 The [[{{smallcaps}}Css{{/smallcaps}} tab>>doc:Formcycle.FormDesigner.CodingPanel.CSSTab.WebHome]] allows you to add your own custom {{smallcaps}}Css{{/smallcaps}} to style the form. To apply a certain style only to some form elements, you can use a {{smallcaps}}Css{{/smallcaps}} selector. The [[JavaScript tab>>doc:Formcycle.FormDesigner.CodingPanel.ScriptTab.WebHome]] lets you use the library jQuery. This library makes use of {{smallcaps}}Css{{/smallcaps}} selectors with some additions. That means that you can use {{smallcaps}}Css{{/smallcaps}} selectors to access elements even when using JavaScript.
4
5 See the help pages for the [[JavaScript tab>>doc:Formcycle.FormDesigner.CodingPanel.ScriptTab.WebHome]] for further details on jQuery.
6
7 See the help pages for the [[{{smallcaps}}Css{{/smallcaps}} tab>>doc:Formcycle.FormDesigner.CodingPanel.CSSTab.WebHome]] for further details on {{smallcaps}}Css{{/smallcaps}}.
8
9 This page gives an overview of selectors in general; and which special selectors you can use for forms created with {{formcycle/}}.
10
11 == Attribute selectors during form creation ==
12
13 === Attribut selector: name ===
14
15 You often need to access a certain form element by its name. To do so you can use the following name selector:
16
17 {{code language="Javascript"}}
18 $("[name='tfMail']") // via jQuery (JavaScript tab)
19 {{/code}}
20
21 {{code language="CSS"}}
22 [name="tfMail"] { /* via CSS (CSS tab)*/
23 color: #DDD;
24 }
25 {{/code}}
26
27 The value of the attribute //name// corresponds to the name of the form element you wish to select. That is, the name you entered in the [[base settings section>>doc:Formcycle.FormDesigner.ElementProperties.BaseProperties]] of the properties panel of the {{designer/}}.
28
29 These name selectors are a special type of attribute selectors. Attribute selectors offer a way to select HTML element by any attribute or attribute value. HTML elements may have any number of attributes:
30
31 {{code language="html"}}
32 <input id="xi-tf-1" class="XItem XTextField" name="tfMail" value="demo@example.com" data-count="9">
33 {{/code}}
34
35 You can now select an element by specifying which attribute it should have or what the value one of its attributes should be. An attribute selector consists of two parts and always looks like this:
36
37 {{code language="css"}}
38 [key="value"]
39 {{/code}}
40
41 ; key
42 : Name of the attribute. Only elements which have got such an attribute are selected.
43 ; value
44 : Value of the attribute. Only elements which have the specified attribute set to this value are selected.
45
46 That is, to select all elements that have got an attribute named //value// (irrespective of the value of this attribute), use {{code language="none"}}[value]{{/code}}. To select only the subset of those elements that have the //value// attribute set to //demo//, use {{code language="none"}}[value="demo"]{{/code}}.
47
48 === Attribute selector: xn ===
49
50 Each form element is put inside a container element. This container consists of the actual form element and additional elements, such as the label for the form element. In case you want to select the container element, use an attribute selector for the attribute //xn// (=xima-name) instead of //name//.
51
52 {{code language="javascript"}}
53 $("[xn='tfMail']"); // via jQuery (JavaScript tab)
54 {{/code}}
55
56 {{code language="css"}}
57 [xn="tfMail"] { /* via CSS (CSS tab)*/
58 font-weight: 600;
59 }
60 {{/code}}
61
62 === Additional attribut selectors ===
63
64 {{code language="javascript"}}
65 // Select all input fields of type "text"
66 $("input[type='text']")
67 {{/code}}
68
69 {{code language="javascript"}}
70 // Select all images with an "alt" attribute
71 $("img[alt]")
72 {{/code}}
73
74 It is also possible to select those element with an attribute value that ends on a certain expression. To do so, use the operator {{code language="none"}}$={{/code}} instead of the equal sign {{code language="none"}}={{/code}}.
75
76 {{code language="javascript"}}
77 // All links, where attribute "href" ends on ".pdf"
78 $("a[href$='.pdf']")
79 {{/code}}
80
81 == Class selectors ==
82
83 HTML defines a special attribute named {{code language="none"}}class{{/code}}. Often this is also referred to as a {{smallcaps}}Css{{/smallcaps}} class. This attribute lets you specify one or multiple classes, separated by a space. Within {{smallcaps}}Css{{/smallcaps}}, that lets you apply certain styles to all elements with a given class. With JavaScript, you can apply a certain feature to all elements of a given class. For example, all form elements generated by {{formcycle/}} have always got the class {{code language="none"}}XItem{{/code}} as well as an additional class that depends on the type of the element, such as [[XTextField>>doc:Formcycle.FormDesigner.FormElements.Input]] or [[XUpload>>doc:Formcycle.FormDesigner.FormElements.Upload]].
84
85 Classes are used pretty often. There exists a special selector for classes that makes it easier to select elements by their classes. To select all elements with a particular class, use a selector that consists of a period, followed by the name of the class. To illustrate, a simple HTML page could look like this:
86
87 {{code language="html"}}
88 <input class="XItem XTextField">
89 <select class="XItem XSelect">
90 <option value="">Please select</option>
91 <option value="1">Option 1</option>
92 <option value="2">Option 2</option>
93 </select>
94 {{/code}}
95
96 Now you can access these elements with selectors:
97
98 {{code language="css"}}
99 /* All elements with the class XItem */
100 .XItem {
101 font-size: 20px; /* Set font size to 20 pixels*/
102 }
103
104 /* Select only input fields (class XTextField) */
105 .XTextField {
106 color: blue; /* Set font color to blue */
107 }
108 {{/code}}
109
110 == Working with selected elements ==
111
112 Once you have select an element, you can use one of the [[many functions>>doc:Formcycle.FormDesigner.CodingPanel.ScriptTab.AdditionalScriptFunctions.WebHome]] offered by jQuery and {{formcycle/}} to edit their values or modify them in other interesting ways.
113
114 {{code language="Javascript"}}
115 // Hide all input fields
116 $("input[type='text']").visible(false)
117
118 // Mark the element with the name "tfZip" as a required field
119 $("[name='tfZip']").setRequired(true)
120 {{/code}}
121
122 === Generic JavaScript functionality ===
123
124 {{figure image="designer_selectors_prefill_en.png"}}
125 Input fields are prefilled with data from the user that is currently signed in. The user data is read from the object //XFC_METADATA.currentUser//. The attribute //data-user// on the input fields controls which property is taken.
126 {{/figure}}
127
128 The {{designer/}} lets you add [[additional classes>>doc:Formcycle.FormDesigner.ElementProperties.CSSClasses]] and [[custom attributes>>doc:Formcycle.FormDesigner.ElementProperties.Attributes]] to a form field. You could write a certain JavaScript feature and apply it to all elements with a particular class or attribute. Then anybody can choose which elements that functionality should be applied by adding the class or attribute in the {{designer/}}. For example:
129
130 {{js}}
131 for (const element of $("[data-user]")) {
132 const prop = element.dataset.user;
133 const value = XFC_METADATA.currentUser[prop];
134 if (value && !element.value) {
135 element.value = value;
136 }
137 }
138 {{/js}}
139
140 {{jsIE}}
141 $("[data-user]").each(function(_, element) {
142 var prop = $(element).data("user");
143 var value = XFC_METADATA.currentUser[prop];
144 if (value && !element.value) {
145 element.value = value;
146 }
147 });
148 {{/jsIE}}
149
150 An input field gets the attribute //data-user//. It is set to a value such as //email// or //forename//. The JavaScript from above then checks whether the currently signed in user has got the specified property (email address, first name etc.). If they do, the input field is prefilled with that value. This way you only need to write a JavaScript feature once. If you upload the JavaScript file as [[client resource>>doc:Formcycle.UserInterface.FilesAndTemplates.Files]], it is available to all forms.
151
152 == Form element selectors ==
153
154 The following selectors are often used when working with {{formcycle/}} forms.
155
156 {{table dataTypeAlpha="0"}}
157 |=Selector|=Description|=Example (jQuery / CSS)
158 |FORM.xm-form|Selects the entire form.|{{code language="javascript"}}$('FORM.xm-form'){{/code}}
159 \\
160 {{code language="css"}}FORM.xm-form {
161 font-family: Arial;
162 }{{/code}}
163 |.class|Selects all elements with the given class. For a list of form element classes, see below.|{{code language="javascript"}}$('.XPage'){{/code}}
164 \\
165 {{code language="css"}}.XPage {
166 background-color: #EEE;
167 }{{/code}}
168 |.required-star|Selects all elements that represent the small red star that marks form fields as required fields.|{{code language="javascript"}}$('.required-star'){{/code}}
169 \\
170 {{code language="css"}}.required-star {
171 color: red;
172 }{{/code}}
173 |.xm-item-div|Each [[Formularelement>>doc:Formcycle.FormDesigner.FormElements.WebHome]] is placed inside a container element. This container element has got the class //xm-item-div//. The container consists of the actual form elements (//<input>//, //<select>// etc.) and additional elements such as the label of the form field. An
174 [[input field>>doc:Formcycle.FormDesigner.FormElements.Input]], for example, consists of a label element and an input element.|{{code language="javascript"}}$('[.xm-item-div]'){{/code}}
175 \\
176 {{code language="css"}}.xm-item-div {
177 font-size: 1.2em;
178 }{{/code}}
179 |.C<KLASSE>|As mentioned, all form elements are put inside a container element. Each form element has got a class depending on its type, such as /XInputText//. The container element then gets the class, prefixed with a //C// (=container), such as //CXInputText//. This selector lets you select all containers with form elements of a particular type. See below for a list of classes.|{{code language="javascript"}}$('[.CXTextField]')
180 $('[.CXCheckbox]')
181 $('[.CXImage]'){{/code}}
182 \\
183 {{code language="css"}}.CXCheckbox label {
184 color: #aaa;
185 }{{/code}}
186 |.xm-form-row|When you palce multiple form elements next to each other, they are placed inside a container element with the class //xm-form-row//.|{{code language="javascript"}}$('[.xm-form-row]'){{/code}}
187 \\
188 {{code language="css"}}.xm-form-row {
189 border-style: solid;
190 }{{/code}}
191 |name|Selects an element with a particular name. This works for all elements, event containers and fieldsets. You should not use this selector for elements that are [[repeatable>>doc:Formcycle.FormDesigner.ElementProperties.BaseProperties||anchor="repeat"]]. When an element is repeated, an index is added to the name. Instead, use the attribute //org_name// to select all repeated elements with that name.|{{code language="javascript"}}$('[name=element]'){{/code}}
192 \\
193 {{code language="css"}}[name="tfName"]{
194 font-weight: 700;
195 }{{/code}}
196 |org_name|When an element is [[repeatable>>doc:Formcycle.FormDesigner.ElementProperties.BaseProperties||anchor="repeat"]], each dynamically created elements receives an additional attribute: //org_name//. The //org_name// is always set to the original name of the element, while an index is added to the //name// attribute.|{{code language="javascript"}}$('[org_name=tf1]'){{/code}}
197 \\
198 {{code language="css"}}[org_name="tfMail"] {
199 margin: 2px;
200 }{{/code}}
201 |xn|Selector the container of a [[Formularelements>>doc:Formcycle.FormDesigner.FormElements.WebHome]] with the given name. Each form element is placed inside a container that also contains additional elements such as the label.|{{code language="javascript"}}$("[xn='tfPhone']"){{/code}}
202 \\
203 {{code language="css"}}[xn="XTextArea"] {
204 font-family: sans-serif;
205 }
206 {{/code}}
207 |cn|Selects all containers with [[form elements>>doc:Formcycle.FormDesigner.FormElements.WebHome]] of a particular type. See below for a list of classes for each form element type.|{{code language="javascript"}}$('[cn=XPage]'){{/code}}
208 \\
209 {{code language="css"}}[cn=XTextField]{
210 font-family: serif;
211 }{{/code}}
212 {{/table}}
213
214 == List of classes ==
215
216 Each type of form elements has got a special {{smallcaps}}Css{{/smallcaps}} class that is used in the form. You can use this class to select all elements of a certain type.
217
218 {{table dataTypeAlpha="0" preSort="0-asc"}}
219 |=Selector|=Description|=Example
220 |XHeader|Selects the header element of the form. The header element is always visible at the top of the form, irrespective of which page is currently shown.|{{code language="javascript"}}$(".XHeader']"){{/code}}
221 |XFooter|Selects the footer element of the form. The footer element is always visible at the bottom of the form, irrespective of which page is currently shown.|{{code language="javascript"}}$(".XFooter']"){{/code}}
222 $("[cn='XPage']"){{/code}}
223 |XPage|Selects all [[pages>>doc:Formcycle.FormDesigner.FormElements.Page]].|{{code language="javascript"}}$(".XPage']")
224 $("[cn='XPage']"){{/code}}
225 |XContainer|Selects all [[containers>>doc:Formcycle.FormDesigner.FormElements.Container]].|{{code language="javascript"}}$(".XContainer']")
226 $("[cn='XContainer']"){{/code}}
227 |XFieldSet|Selects all [[fieldsets>>doc:Formcycle.FormDesigner.FormElements.Fieldset]].|{{code language="javascript"}}$(".XFieldSet")
228 $("[cn='XFieldSet']"){{/code}}
229 |XSpan|Selects all [[texts>>doc:Formcycle.FormDesigner.FormElements.Text]].|{{code language="javascript"}}$(".XSpan")
230 $("[cn='XSpan']"){{/code}}
231 |XTextArea|Selects all [[text areas>>doc:Formcycle.FormDesigner.FormElements.Textarea]].|{{code language="javascript"}}$(".XTextArea")
232 $("[cn='XTextArea']"){{/code}}
233 |XTextField|Selects all [[input fields>>doc:Formcycle.FormDesigner.FormElements.Input]].|{{code language="javascript"}}$(".XTextField")
234 $("[cn='XTextField']"){{/code}}
235 |XCheckbox|Selects all form elements of type [[checkbox>>doc:Formcycle.FormDesigner.FormElements.Checkbox]].|{{code language="javascript"}}$(".XCheckbox")
236 $("[cn='XCheckbox']"){{/code}}
237 |XSelect|Selects all [[selection elements>>doc:Formcycle.FormDesigner.FormElements.Selection]].|{{code language="javascript"}}$(".XSelect")
238 $("[cn='XSelect']"){{/code}}
239 |XLine|Selects all [[lines>>doc:Formcycle.FormDesigner.FormElements.Line]].|{{code language="javascript"}}$(".XLine")
240 $("[cn='XLine']"){{/code}}
241 |XImage|Selects all [[images>>doc:Formcycle.FormDesigner.FormElements.Image]].|{{code language="javascript"}}$(".XImage")
242 $("[cn='XImage']"){{/code}}
243 |XSpacer|Selects all [[spacing elements>>doc:Formcycle.FormDesigner.FormElements.Spacer]].|{{code language="javascript"}}$(".XSpacer")
244 $("[cn='XSpacer']"){{/code}}
245 |XUpload|Selects all [[upload elements>>doc:Formcycle.FormDesigner.FormElements.Upload]].|{{code language="javascript"}}$(".XUpload")
246 $("[cn='XUpload']"){{/code}}
247 |XButtonList|Selects all [[buttons>>doc:Formcycle.FormDesigner.FormElements.Button]].|{{code language="javascript"}}$(".XButtonList")
248 $("[cn='XButtonList']"){{/code}}
249 |XDropDown|Selects the SELECT element of a select form field (//XSelect//), when its display mode is set to //drop down list//.|{{code language="javascript"}}$(".XDropDown"){{/code}}
250 |XList|Selects the SELECT element of a select form field (//XSelect//), when its display mode is set to //inline list of options//.|{{code language="javascript"}}$(".XList"){{/code}}
251 |XCheckbox|Additionally, this also selects the container DIV elements of select form fields (//XSelect//), when their display mode is set to //checkboxes//.|{{code language="javascript"}}$(".XCheckbox"){{/code}}
252 |XRadio|Selects the container DIV element with all radio buttons of a select form field (//XSelect//), when its display mode is set to //radio buttons//.|{{code language="javascript"}}$(".XRadio"){{/code}}
253 |CXTable|Selects the container DIV element with all questions of a select form field (//XSelect//), when its display mode is set to //questionnaire//.|{{code language="javascript"}}$(".CXTable"){{/code}}
254 {{/table}}
Copyright 2000-2024