-
Notifications
You must be signed in to change notification settings - Fork 8
/
input.js
57 lines (47 loc) · 1.29 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
/**
* form input tag
*
* Syntax:
* {% input name "label" "placeholder" "help" textarea|email|password|select sm|lg required %}
*/
// <div class="form-group">
// <label for="name" class="required">Name</label>
// <input id="name" type="text" name="name">
// </div>
var sizes = {sm:true, lg:true};
var types = {textarea:true, email:true, password: true, select:true};
module.exports = function(args, content){
var name = args[0];
var label = args[1];
var placeholder = args[2];
var help = "";
var style = "form-control";
var required = false;
var size;
var type;
var control = "input";
var controlEnd = "</input>";
for(var i = 2; i < args.length; i++) {
var val = args[i];
if(val === "required")
required = true;
else if(types[val])
type = val;
else if(sizes[val])
size = val;
else
help = val;
}
if(size) {
style = style + " form-control-" + size;
}
if(help.length > 0) {
help = '<small class="form-text text-muted">'+help+'</small>';
}
if(type === "textarea") {
control = 'textarea rows="3"';
controlEnd = "</textarea>";
} else if(type = "checkbox") {
}
return '<div class="form-group"><label for="formCtrl'+name+'"></label><'+control+' id="formCtrl'+name+'" style="'+style+'" name="'+name+'" type="'+type+'" >'+controlEnd + help+'</div>'
};