-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinput.js
executable file
·34 lines (29 loc) · 1.38 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
class Input {
constructor(params) {
this.id = params.id ? params.id : 'input-' + Math.floor(Math.random() * 101);
this.holder = params.holder ? params.holder : '';
this.title = params.title ? params.title : '';
this.type = params.type ? params.type : undefined;
this.placeholder = params.placeholder ? params.placeholder : '';
this.hint = params.hint ? params.hint : '';
this.disable = params.disable ? 'readonly' : '';
this.col = params.col ? params.col : undefined;
if (this.holder) {
$('#' + this.holder).html(this.render());
}
}
render() {
let col = '';
if (this.col) {
col = `col-md-${this.col}`;
}
if(this.type === 'hidden'){
return `<input type="${this.type}" class="form-control" id="${this.id}" name="${this.id}" aria-describedby="${this.id}Help" placeholder="${this.placeholder}" ${this.disable}>`;
}
return `<div class="form-group ${col}">
<label for="${this.id}">${this.title}</label>
<input type="${this.type}" class="form-control" id="${this.id}" name="${this.id}" aria-describedby="${this.id}Help" placeholder="${this.placeholder}" ${this.disable}>
<small id="${this.id}Help" class="form-text text-muted">${this.hint}</small>
</div>`;
}
}