30 Star 85 Fork 18

drinkjava2 / GoSqlGo

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
demo3.html 2.78 KB
Copy Edit Web IDE Raw Blame History
drinkjava2 authored 2019-05-14 08:03 . node.js done, randomId cache done
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.msg { width: 80%; padding: 8px; margin-bottom: 20px;}
.normalMsg {background: #dfb}
.errorMsg {background: #ffbeb8}
</style>
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/jquery-ajax-ext.js"></script>
<script src="/js/gosqlgo.js"></script>
</head>
<body>
<script>
document.write($java(`return new WebBox("/page/menu.html").setAttribute("title", $1);`, "Form validation demo") );
</script>
<div id="msg" class="msg"></div>
<br />
<script>
$java(`FULL package ab.cd;
import static com.github.drinkjava2.jsqlbox.JSQLBOX.gctx;
import com.github.drinkjava2.jdialects.StrUtils;
import com.github.drinkjava2.jsqlbox.ActiveEntity;
public class UserDemo implements ActiveEntity<UserDemo> {
static {
for (String ddl : gctx().toCreateDDL(UserDemo.class))
gctx().nExecute(ddl);
}
String name;
String identity;
String phoneNumber;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String inputCheck() {
StringBuilder error = new StringBuilder();
if (StrUtils.isEmpty(getName()))
error.append("Name can not be empty; <br/>");
if (StrUtils.isEmpty(getIdentity()))
error.append("Identity can not be empty; <br/> ");
if (StrUtils.isEmpty(getPhoneNumber()))
error.append("Phone_number can not be empty; <br/>");
return error.toString();
}
}
`);
function postForm(){
var rst = $java(`import ab.cd.UserDemo;
UserDemo u= JSON.parseObject($1, UserDemo.class);
String error = u.inputCheck();
if (error.isEmpty()) {
u.insert();
return "msg:UserDemo saved, now have "+eCountAll(UserDemo.class)+" records.";
} else
return "error:" + error;
`, formToJSON("form1"));
if(rst.indexOf("msg:")==0){
$("#msg").html(rst.substring(4));
$("#msg").css("background", "#dfb");
} else if(rst.indexOf("error:")==0){
$("#msg").html(rst.substring(6));
$("#msg").css("background", "#ffbeb8");
}
}
</script>
<form id="form1" name="form1" onsubmit="return false" action="##"
method="post">
Name:<br /> <input type="text" name="name" value="" /><br /> Identity:
<br />
<input type="text" name="identity" value="" /><br /> Phone Number: <br />
<input type="text" name="phoneNumber" value="" /><br />
<br />
<button name="Submit" value="true" onclick="postForm()">Submit</button>
</form>
</body>
</html>

Comment ( 0 )

Sign in for post a comment

Java
1
https://gitee.com/drinkjava2/gosqlgo.git
git@gitee.com:drinkjava2/gosqlgo.git
drinkjava2
gosqlgo
GoSqlGo
master

Search