-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
208 lines (183 loc) · 7.56 KB
/
index.html
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multiline control demo</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="src/jquery.multiline-control.js"></script>
<style>
body {
margin: 70px 0;
}
.arrow-example {
padding: 10px;
font-size: 100px;
}
h2 {
margin-bottom: 40px;
margin-top: 40px;
}
.nav i.fa {
font-size: 18px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-1"
aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Multiline control</a>
</div>
<div class="collapse navbar-collapse" id="bs-navbar-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/vedmant/multiline-control/zipball/master"><i
class="glyphicon glyphicon-download-alt"></i> Download zip</a></li>
<li><a href="https://github.com/vedmant/multiline-control/tarball/master"><i
class="glyphicon glyphicon-download-alt"></i> Download tar.gz</a></li>
<li><a href="https://github.com/vedmant/multiline-control"><i class="fa fa-github"></i> GitHub</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h2>Textarea to Multiline control</h2>
<div class="row">
<div class="col-md-5">
<div class="form-group">
<label>Turn your textarea</label>
<textarea class="form-control initial" rows="4">[email protected]
[email protected]</textarea>
</div>
</div>
<div class="col-md-2 text-center">
<i class="glyphicon glyphicon-arrow-right arrow-example hidden-xs hidden-sm"></i>
<i class="glyphicon glyphicon-arrow-down arrow-example visible-xs visible-sm"></i>
</div>
<div class="col-md-5">
<form id="test_form">
<div class="form-group">
<label>To line-by-line editor with validation and sorting</label>
<textarea name="emails" class="form-control multiline-control">[email protected]
[email protected]</textarea>
</div>
</form>
</div>
</div>
<h2>How to use</h2>
<pre>
<!-- Add textarea -->
<textarea class="form-control multiline-control"></textarea>
<!-- Include jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Include plugin file -->
<script src="js/multiline-control.min.js"></script>
<!-- Initialize plugin for .multiline-control class elements -->
<script>
jQuery(function ($) {
$('.multiline-control').multiline_control();
});
</script>
</pre>
<h2>Full options list (default values)</h2>
<pre>
$('.multiline-control').multiline_control({
sortable: true,
templateContainer: '<div class="multiline-control"></div>',
templateAddBtn: '<a href="#" class="mc-add-btn btn btn-success btn"><i class="glyphicon glyphicon-plus"></i></a>',
templateLine:
'<div class="form-group mc-row">' +
'<div class="input-group">' +
'{sorting_handle}' +
'<input type="text" class="form-control" name="{name}" value="{value}">' +
'<a href="#" class="input-group-addon btn btn-default btn-sm mc-remove-btn">' +
'<i class="glyphicon glyphicon-remove"></i>' +
'</a>' +
'</div>' +
'</div>',
templateHandle: '<div class="input-group-addon mc-handle" style="cursor: move;"><i class="glyphicon glyphicon-move"></i></div>',
templateSortablePlaceholder: '<div class="mc-sortable-placeholder form-group form-control" style="border: 1px dashed blue;"></div>',
onChange: $.noop
});
</pre>
<h2>Validation support</h2>
This plugin supports vallidation based on <a href="https://jqueryvalidation.org/">https://jqueryvalidation.org/</a> with following settings:
<pre>
$('#test_form').validate({
onkeyup: function (element) { $(element).valid() },
rules: {
'emails_mc[]': 'email',
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
},
});
</pre>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>
<script>
jQuery( function( $ ) {
var $initial_textarea = $( '.initial' );
var $multiline_control = $( '.multiline-control' );
$multiline_control.multiline_control( {
onChange: function( value ) {
$initial_textarea.val( value );
}
} );
$initial_textarea.change(function( e ) {
$multiline_control.multiline_control( 'update', $( this ).val() );
});
$('#test_form').validate({
onkeyup: function (element) { $(element).valid() },
rules: {
'emails_mc[]': 'email',
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
},
});
} );
</script>
</body>
</html>