File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
UI Actions/Add collapsible element in knowledge article Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ This code snippet will allow you to use collapsible element within knowledge atricle which will make articles clean, organized and effective.
2
+
3
+ ![ Demo] ( https://github.com/abhrajyotikanrar/code-snippets/assets/25823899/e3ad356e-a5c5-4f2d-aafa-20f89b0da248 )
4
+
5
+ Please check out the above demo on how this code-snippet can be used.
Original file line number Diff line number Diff line change
1
+ /*
2
+ This script should be placed in the UI action on the table kb_knowledge form view.
3
+ This UI action should be marked as client.
4
+ Use addCollapsible() function in the Onclick field.
5
+ */
6
+
7
+ function addCollapsible ( ) {
8
+ var gm = new GlideModal ( "add_collapsible" ) ;
9
+ gm . setTitle ( 'Add collapsible' ) ;
10
+ gm . setWidth ( 1000 ) ;
11
+ gm . render ( ) ;
12
+ }
Original file line number Diff line number Diff line change
1
+ * ** ** * HTML ** * **
2
+ < ?xml version = "1.0" encoding = "utf-8" ?>
3
+ < j :jelly trim = "false" xmlns :j = "jelly:core" xmlns :g = "glide" xmlns :j2 = "null" xmlns :g2 = "null" >
4
+
5
+ < style >
6
+ .hide{
7
+ visibility : hidden ;
8
+ }
9
+ .show{
10
+ visibility : visible ;
11
+ }
12
+ </ style >
13
+
14
+ < label for = "collapsibleTitle" > Title</ label >
15
+ < input type = "text" class = "form-control" id = "collapsibleTitle" placeholder = "Your collapsible title goes here" />
16
+
17
+ < br />
18
+
19
+ < label for = "collapsibleContent" > Content body</ label >
20
+ < textarea class = "form-control" id = "collapsibleContent" rows = "3" > </ textarea >
21
+
22
+ < br />
23
+
24
+ < div class = "alert alert-danger hide" id = "alert" role = "alert" >
25
+ < b > Title</ b > and < b > Content body</ b > should not be empty.
26
+ </ div >
27
+
28
+ < br />
29
+
30
+ < button type = "button" class = "btn btn-primary" style = "float: right;" onclick = "updateForm()" > Add collapsible</ button >
31
+ </ j :jelly >
32
+ ****************
33
+
34
+ **Client Script**
35
+ function updateForm() {
36
+ $j ( "#alert" ) . removeClass ( "show" ) ;
37
+ $j ( "#alert" ) . addClass ( "hide" ) ;
38
+
39
+ var title = $j ( "#collapsibleTitle" ) . val ( ) ;
40
+ var content = $j ( "#collapsibleContent" ) . val ( ) ;
41
+
42
+ if ( title . trim ( ) == "" || content . trim ( ) == "" ) {
43
+ $j ( "#alert" ) . removeClass ( "hide" ) ;
44
+ $j ( "#alert" ) . addClass ( "show" ) ;
45
+
46
+ return ;
47
+ }
48
+
49
+ var articleText = g_form.getValue("text");
50
+ var collapsibleElement = "< details style = 'width: 100%; border: 1px solid #ccc;' > < summary style = 'cursor: pointer; padding: 15px; background: #e8e8e8;' > " + title.trim() + "</ summary > < div style = 'padding: 15px;' > " + content.trim() + "</ div > </ details > ";
51
+
52
+ g_form.setValue("text", articleText + collapsibleElement);
53
+ GlideDialogWindow.get().destroy()
54
+ }
You can’t perform that action at this time.
0 commit comments