dynamic validation (#1621)

* dynamic validation

* small fixes
This commit is contained in:
lor6
2017-04-12 14:38:44 +03:00
committed by KevinGilmore
parent 0b98f0d211
commit 2f34e89546
11 changed files with 302 additions and 0 deletions
@@ -0,0 +1,3 @@
insert into contact_info_expression values ('email','[a-z0-9!#$%&*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?')
insert into contact_info_expression values ('phone','^([0-9]( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4}|[a-zA-Z0-9]{7})$')
insert into contact_info_expression values ('website','^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$')
@@ -0,0 +1,5 @@
create table contact_info_expression(
expression_type varchar(50) not null,
pattern varchar(500) not null,
PRIMARY KEY ( expression_type )
);
@@ -0,0 +1,41 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Customer Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
url: "contactInfoTypes"
}).done(function(data) {
var contactInfoType = $('#contactInfoType').text();
$.each(data,function(key, value) {
var o = new Option(value.type, value.type);
if (value.type == contactInfoType) {
o.selected = true;
}
$('#expressions').append(o);
});
});
$('#expressions').change(function(){
$.ajax({
url: "updateContactInfoType",
method:'POST',
data:{type:$('#expressions').val()}
});
});
});
</script>
</head>
<body>
<br />
<form action="customer" method="POST">
Contact Info: <input type="text" name="contactInfo" /> <br />
Contact Info Type: <select id="expressions" ></select> <br />
<input type="submit" value="Submit" />
</form>
<br /><br />
<span th:text="${message}"></span><br />
<span id="contactInfoType" th:text="${contactInfoType}" style="visibility:hidden"></span><br />
</body>
</html>