-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomJSSSS.js
More file actions
166 lines (152 loc) · 5.82 KB
/
customJSSSS.js
File metadata and controls
166 lines (152 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const Input = Formio.Components.components.input;
class myInputs extends Input{
static schema(...extend){
return Input.schema({
type: 'mycomp',
label: 'My Component',
key: 'mycomp'
});
}
static get builderInfo(){
return {
title: 'My Component',
icon: 'terminal',
group: 'basic',
documentation: '/userguide/#textfield',
weight: 0,
schema: myInputs.schema()
}
}
constructor(component, options, data) {
super(component, options, data);
}
init(){
super.init();
}
get inputInfo() {
const info = super.inputInfo;
return info;
}
render(content) {
return super.render('<div ref="customRef">This is a custom component!</div>');
}
attach(element) {
/**
* This method will look for an element that has the 'ref="customRef"' as an
* attribute (like <div ref="customRef"></div>) and then assign that DOM
* element to the variable "this.refs". After this method is executed, the
* following will point to the DOM element of that reference.
*
* this.refs.customRef
*
* For DOM elements that have multiple in the component, you would make this
* say 'customRef: "multiple"' which would then turn "this.refs.customRef" into
* an array of DOM elements.
*/
this.loadRefs(element, {
customRef: 'single',
});
/**
* It is common to attach events to your "references" within your template.
* This can be done with the "addEventListener" method and send the template
* reference to that object.
*/
this.addEventListener(this.refs.customRef, 'click', () => {
console.log('Custom Ref has been clicked!!!');
});
return super.attach(element);
}
detach() {
return super.detach();
}
/**
* Called when the component has been completely "destroyed" or removed form the
* renderer.
*
* @return - A Promise that resolves when this component is done being destroyed.
*/
destroy() {
return super.destroy();
}
/**
* A very useful method that will take the values being passed into this component
* and convert them into the "standard" or normalized value. For exmample, this
* could be used to convert a string into a boolean, or even a Date type.
*
* @param value - The value that is being passed into the "setValueAt" method to normalize.
* @param flags - Change propogation flags that are being used to control behavior of the
* change proogation logic.
*
* @return - The "normalized" value of this component.
*/
normalizeValue(value, flags = {}) {
return super.normalizeValue(value, flags);
}
/**
* Returns the value of the "view" data for this component.
*
* @return - The value for this whole component.
*/
getValue() {
return super.getValue();
}
/**
* Much like "getValue", but this handles retrieving the value of a single index
* when the "multiple" flag is used within the component (which allows them to add
* multiple values). This turns a single value into an array of values, and this
* method provides access to a certain index value.
*
* @param index - The index within the array of values (from the multiple flag)
* that is getting fetched.
*
* @return - The view data of this index.
*/
getValueAt(index) {
return super.getValueAt(index);
}
/**
* Sets the value of both the data and view of the component (such as setting the
* <input> value to the correct value of the data. This is most commonly used
* externally to set the value and also see that value show up in the view of the
* component. If you wish to only set the data of the component, like when you are
* responding to an HMTL input event, then updateValue should be used instead since
* it only sets the data value of the component and not the view.
*
* @param value - The value that is being set for this component's data and view.
* @param flags - Change propogation flags that are being used to control behavior of the
* change proogation logic.
*
* @return - Boolean indicating if the setValue changed the value or not.
*/
setValue(value, flags = {}) {
return super.setValue(value, flags);
}
/**
* Sets the value for only this index of the component. This is useful when you have
* the "multiple" flag set for this component and only wish to tell this component
* how the value should be set on a per-row basis.
*
* @param index - The index within the value array that is being set.
* @param value - The value at this index that is being set.
* @param flags - Change propogation flags that are being used to control behavior of the
* change proogation logic.
*
* @return - Boolean indiciating if the setValue at this index was changed.
*/
setValueAt(index, value, flags = {}) {
return super.setValueAt(index, value, flags);
}
/**
* Similar to setValue, except this does NOT update the "view" but only updates
* the data model of the component.
*
* @param value - The value of the component being set.
* @param flags - Change propogation flags that are being used to control behavior of the
* change proogation logic.
*
* @return - Boolean indicating if the updateValue changed the value or not.
*/
updateValue(value, flags = {}) {
return super.updateValue(...args);
}
}