This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathInput.js
160 lines (154 loc) · 3.08 KB
/
Input.js
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
import core from 'metal';
import templates from './Input.soy.js';
import Component from 'metal-component';
import Soy from 'metal-soy';
class Input extends Component {
created() {
this.isShowing_ = this.initialShow;
if (this.editableWhileVisible) {
if (!this.value || (this.value && this.valeu === '')) {
this.isShowing_ = true;
this.readonly = false;
} else {
if (this.isShowing_) {
this.readonly = false;
} else {
this.readonly = true;
}
}
}
}
toggle() {
this.isShowing_ = !this.isShowing_;
if (this.editableWhileVisible) {
if (this.isShowing_) {
this.readonly = false;
} else {
this.readonly = true;
}
}
}
}
Soy.register(Input, templates);
Input.STATE = {
/**
* Defines "autocomplete" html attribute [on/off]
* @type {string}
* @default 'on'
*/
autocomplete: {
validator: core.isString,
value: 'on',
},
/**
* Defines which classes this input field should have
* @type {string}
*/
classes: {
validator: core.isString,
},
/**
* Defines if while exposed state, the related field shall be editable
* It only works combined with isTogglePassword
* @type {boolean}
*/
editableWhileVisible: {
validator: core.isBoolean,
value: false,
},
/**
* Defines the index of the field
* @type {number}
*/
fieldIndex: {
validator: core.isNumber,
},
/**
* Defines if the value will appear as password or not when it starts
* It only works combined with isTogglePassword
* @type {boolean}
* @default false
*/
initialShow: {
validator: core.isBoolean,
value: false,
},
/**
* Defines the internal value that controls the related field logic visibility
* @type {boolean}
* @default false
*/
isShowing_: {
validator: core.isBoolean,
value: false,
internal: true,
},
/**
* Defines if this field has a behavior to hide and show the value
* @type {boolean}
* @default false
*/
isTogglePassword: {
validator: core.isBoolean,
value: false,
},
/**
* Defines the maximum length for this field.
* @type {number}
*/
maxLength: {
validator: core.isNumber,
},
/**
* Defines the function name to 'oninput' event
* @type {function}
*/
onInput: {
validator: core.isFunction,
},
/**
* Defines "name" html attribute
* @type {string}
*/
name: {
validator: core.isString,
},
/**
* Defines "placeholder" html attribute
* @type {string}
*/
placeholder: {
validator: core.isString,
},
/**
* Defines "readonly" html attribute
* @type {boolean}
*/
readonly: {
validator: core.isBoolean,
},
/**
* Defines which row this field belongs to
* @type {number}
*/
rowIndex: {
validator: core.isNumber,
},
/**
* @type {string}
* @default 'text'
*/
type: {
validator: core.isString,
value: 'text',
},
/**
* Defines the current value
* @type {string}
*/
value: {
validator: core.isString,
},
};
export {Input};
export default Input;