-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): 📝 update the examples: add contenteditable field
- Loading branch information
1 parent
8d4b847
commit 98e7b3a
Showing
8 changed files
with
322 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<Doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Smart Form Validator - ES Module Examples</title> | ||
<link rel="stylesheet" href="../../dist/css/smart-form-validator.min.css" /> | ||
<link rel="stylesheet" href="../examples.css" /> | ||
</head> | ||
<body> | ||
<ul> | ||
<li><a href="./">Back</a></li> | ||
</ul> | ||
|
||
<h3>Input elements belonging to an HTML form</h3> | ||
<form id="test-form"> | ||
<input type="text" id="name-field" role="presentation" autocomplete="off" placeholder="Firstname" /> | ||
<input type="email" id="email-field" role="presentation" autocomplete="off" placeholder="Email" /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> | ||
</form> | ||
|
||
<script type="module"> | ||
import SmartFormValidator from "../../dist/esm/smart-form-validator.js"; // import the SmartFormValidator | ||
|
||
const form = document.getElementById("test-form"); | ||
const name = document.getElementById("name-field"); | ||
const email = document.getElementById("email-field"); | ||
|
||
// When a form has an `<input type="submit" or | ||
// an element with `role="submit-button", | ||
// adding the submit button via `addField()` is optional. | ||
new SmartFormValidator() | ||
.addForm(form) | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) | ||
.addRule({ field: "email-field", type: "email" }) | ||
.watch(); | ||
</script> | ||
|
||
<h3>Code</h3> | ||
<code> | ||
<form id="test-form"> <br /> | ||
<input type="text" id="name-field" /> <br /> | ||
<input type="email" id="email-field" /> <br /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> <br /> | ||
</form> <br /><br /> | ||
|
||
<script type="module"> <br /> | ||
// import `SmartFormValidator` <br /> | ||
import SmartFormValidator from "https://cdn.jsdelivr.net/npm/smart-form-validator/dist/esm/smart-form-validator.js"; | ||
<br /><br /> | ||
|
||
const form = document.getElementById("test-form"); <br /> | ||
const name = document.getElementById("name-field"); <br /> | ||
const email = document.getElementById("email-field"); <br /><br /> | ||
|
||
// When a form has an `<input type="submit" or <br /> | ||
// an element with `role="submit-button", <br /> | ||
// adding the submit button via `addField()` is optional. <br /> | ||
new SmartFormValidator() <br /> | ||
.addForm(form) <br /> | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) <br /> | ||
.addRule({ field: "email-field", type: "email" }) <br /> | ||
.watch(); <br /> | ||
</script> | ||
</code> | ||
<br /><br /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,13 @@ | ||
<Doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Smart Form Validator - ES Module Examples</title> | ||
<link rel="stylesheet" href="../../dist/css/smart-form-validator.min.css" /> | ||
<link rel="stylesheet" href="../examples.css" /> | ||
</head> | ||
<body> | ||
<ul> | ||
<li><a href="../">Back</a></li> | ||
<li><a href="../">Examples home</a></li> | ||
<li><a href="isolated-elements.html">Stand-alone input elements</a></li> | ||
<li><a href="form-elements.html">Input elements as part of a form</a></li> | ||
</ul> | ||
|
||
<h3>Stand-alone input elements</h3> | ||
<div> | ||
<input id="firstname-field" type="text" role="presentation" autocomplete="off" placeholder="Firstname" /> | ||
<input id="accept-terms-field" type="checkbox" /> Accept terms | ||
</div> | ||
|
||
<input id="submit-button" type="submit" value="Submit Form" /> | ||
|
||
<script type="module"> | ||
import SmartFormValidator from "../../dist/esm/smart-form-validator.js"; // import the SmartFormValidator module | ||
|
||
const firstnameField = document.getElementById("firstname-field"); | ||
const acceptTermsField = document.getElementById("accept-terms-field"); | ||
const firstnameRule = { length: { min: 3, max: 5 } }; | ||
const acceptTermsRule = { type: "checkbox", required: true }; | ||
const submitButton = document.getElementById("submit-button"); | ||
const formValidator = new SmartFormValidator(); | ||
|
||
formValidator.addField(firstnameField, firstnameRule); | ||
formValidator.addField(acceptTermsField, acceptTermsRule); | ||
formValidator.addField(submitButton); | ||
formValidator.watch(); | ||
</script> | ||
|
||
<p> </p> | ||
|
||
<h3>Code</h3> | ||
<code> | ||
<head> <br /> | ||
<link <br /> | ||
href="https://cdn.jsdelivr.net/npm/smart-form-validator/dist/css/smart-form-validator.min.css" <br /> | ||
rel="stylesheet" /> <br /> | ||
</head> <br /><br /> | ||
... | ||
<br /><br /> | ||
<input id="firstname-field" type="text" /> <br /> | ||
<input id="accept-terms-field" type="checkbox" /> Accept terms <br /> | ||
<input id="submit-button" type="submit" value="Submit Form" /> <br /><br /> | ||
|
||
<script type="module"> <br /> | ||
import SmartFormValidator from "https://cdn.jsdelivr.net/npm/smart-form-validator/dist/esm/smart-form-validator.js"; // import the SmartFormValidator | ||
<br /><br /> | ||
|
||
const firstnameField = document.getElementById("firstname-field"); <br /> | ||
const acceptTermsField = document.getElementById("accept-terms-field"); <br /> | ||
const firstnameRule = { length: { min: 3, max: 5 } }; <br /> | ||
const acceptTermsRule = { type: "checkbox", required: true }; <br /> | ||
const submitButton = document.getElementById("submit-button"); <br /> | ||
const formValidator = new SmartFormValidator(); <br /><br /> | ||
|
||
formValidator.addField(firstnameField, firstnameRule); <br /> | ||
formValidator.addField(acceptTermsField, acceptTermsRule); <br /> | ||
formValidator.addField(submitButton); <br /> | ||
formValidator.watch(); <br /> | ||
</script> | ||
</code> | ||
|
||
<br /><br /> | ||
|
||
<hr /> | ||
|
||
<h3>Input elements belonging to an HTML form</h3> | ||
<form id="test-form"> | ||
<input type="text" id="name-field" role="presentation" autocomplete="off" placeholder="Firstname" /> | ||
<input type="email" id="email-field" role="presentation" autocomplete="off" placeholder="Email" /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> | ||
</form> | ||
|
||
<script type="module"> | ||
import SmartFormValidator from "../../dist/esm/smart-form-validator.js"; // import the SmartFormValidator | ||
|
||
const form = document.getElementById("test-form"); | ||
const name = document.getElementById("name-field"); | ||
const email = document.getElementById("email-field"); | ||
|
||
// When a form has an `<input type="submit" or | ||
// an element with `role="submit-button", | ||
// adding the submit button via `addField()` is optional. | ||
new SmartFormValidator() | ||
.addForm(form) | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) | ||
.addRule({ field: "email-field", type: "email" }) | ||
.watch(); | ||
</script> | ||
|
||
<h3>Code</h3> | ||
<code> | ||
<form id="test-form"> <br /> | ||
<input type="text" id="name-field" /> <br /> | ||
<input type="email" id="email-field" /> <br /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> <br /> | ||
</form> <br /><br /> | ||
|
||
<script type="module"> <br /> | ||
import SmartFormValidator from "https://cdn.jsdelivr.net/npm/smart-form-validator/dist/esm/smart-form-validator.js"; // import the SmartFormValidator | ||
<br /><br /> | ||
|
||
const form = document.getElementById("test-form"); <br /> | ||
const name = document.getElementById("name-field"); <br /> | ||
const email = document.getElementById("email-field"); <br /><br /> | ||
|
||
// When a form has an `<input type="submit" or <br /> | ||
// an element with `role="submit-button", <br /> | ||
// adding the submit button via `addField()` is optional. <br /> | ||
new SmartFormValidator() <br /> | ||
.addForm(form) <br /> | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) <br /> | ||
.addRule({ field: "email-field", type: "email" }) <br /> | ||
.watch(); <br /> | ||
</script> | ||
</code> | ||
|
||
<br /><br /><br /> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<Doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Smart Form Validator - ES Module Examples</title> | ||
<link rel="stylesheet" href="../../dist/css/smart-form-validator.min.css" /> | ||
<link rel="stylesheet" href="../examples.css" /> | ||
</head> | ||
<body> | ||
<ul> | ||
<li><a href="./">Back</a></li> | ||
</ul> | ||
|
||
<h3>Stand-alone input elements</h3> | ||
<div> | ||
<input id="firstname-field" type="text" role="presentation" autocomplete="off" placeholder="Firstname" /> | ||
<p id="free-text-paragraph" contenteditable="true" data-placeholder="contenteditable field"></p> | ||
</div> | ||
|
||
<div> | ||
<input id="accept-terms-field" type="checkbox" /> Accept terms | ||
</div> | ||
|
||
<input id="submit-button" type="submit" value="Submit Form" /> | ||
|
||
<script type="module"> | ||
import SmartFormValidator from "../../dist/esm/smart-form-validator.js"; // import the SmartFormValidator module | ||
|
||
const firstnameField = document.getElementById("firstname-field"); | ||
const acceptTermsField = document.getElementById("accept-terms-field"); | ||
const firstnameRule = { length: { min: 3, max: 5 } }; | ||
const acceptTermsRule = { type: "checkbox", required: true }; | ||
const submitButton = document.getElementById("submit-button"); | ||
const formValidator = new SmartFormValidator(); | ||
|
||
formValidator.addField(firstnameField, firstnameRule); | ||
formValidator.addField("free-text-paragraph", { type: "ascii", length: { min: 5, max: 50 } }); | ||
formValidator.addField(acceptTermsField, acceptTermsRule); | ||
formValidator.addField(submitButton); | ||
formValidator.watch(); | ||
</script> | ||
|
||
<p> </p> | ||
|
||
<h3>Code</h3> | ||
<code> | ||
<head> <br /> | ||
<link <br /> | ||
href="https://cdn.jsdelivr.net/npm/smart-form-validator/dist/css/smart-form-validator.min.css" <br /> | ||
rel="stylesheet" /> <br /> | ||
</head> <br /><br /> | ||
... | ||
<br /><br /> | ||
<input id="firstname-field" type="text" /> <br /> | ||
<p id="free-text-paragraph" contenteditable="true"></p> <br /> | ||
<input id="accept-terms-field" type="checkbox" /> Accept terms <br /> | ||
<input id="submit-button" type="submit" value="Submit Form" /> <br /><br /> | ||
|
||
<script type="module"> <br /> | ||
// import `SmartFormValidator` <br /> | ||
import SmartFormValidator from "https://cdn.jsdelivr.net/npm/smart-form-validator/dist/esm/smart-form-validator.js"; | ||
<br /><br /> | ||
|
||
const firstnameField = document.getElementById("firstname-field"); <br /> | ||
const acceptTermsField = document.getElementById("accept-terms-field"); <br /> | ||
const firstnameRule = { length: { min: 3, max: 5 } }; <br /> | ||
const acceptTermsRule = { type: "checkbox", required: true }; <br /> | ||
const submitButton = document.getElementById("submit-button"); <br /> | ||
const formValidator = new SmartFormValidator(); <br /><br /> | ||
|
||
formValidator.addField(firstnameField, firstnameRule); <br /> | ||
formValidator.addField("free-text-paragraph", { type: "ascii", length: { min: 5, max: 50 } }); <br /> | ||
formValidator.addField(acceptTermsField, acceptTermsRule); <br /> | ||
formValidator.addField(submitButton); <br /> | ||
formValidator.watch(); <br /> | ||
</script> | ||
</code> | ||
<br /><br /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<Doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Smart Form Validator - Browser Examples</title> | ||
<link rel="stylesheet" href="../../dist/css/smart-form-validator.min.css" /> | ||
<link rel="stylesheet" href="../examples.css" /> | ||
<script type="text/javascript" src="../../dist/smart-form-validator.js"></script> | ||
</head> | ||
<body> | ||
<ul> | ||
<li><a href="./">Back</a></li> | ||
</ul> | ||
|
||
<h3>Input elements belonging to an HTML form</h3> | ||
<form id="test-form" style="text-align: left;"> | ||
<input type="text" id="name-field" role="presentation" autocomplete="off" placeholder="Enter your name" /> | ||
<input type="email" id="email-field" role="presentation" autocomplete="off" placeholder="Enter your email" /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
const form = document.getElementById("test-form"); | ||
const name = document.getElementById("name-field"); | ||
const email = document.getElementById("email-field"); | ||
|
||
// When a form has an `<input type="submit" or | ||
// an element with `role="submit-button", | ||
// adding the submit button via `addField()` is optional. | ||
new SmartFormValidator() | ||
.addForm(form) | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) | ||
.addRule({ field: "email-field", type: "email" }) | ||
.watch(); | ||
</script> | ||
|
||
<p> </p> | ||
|
||
<h3>Code</h3> | ||
<code> | ||
<head> <br /> | ||
<link <br /> | ||
href="https://cdn.jsdelivr.net/npm/smart-form-validator/dist/css/smart-form-validator.min.css" <br /> | ||
rel="stylesheet" /> <br /> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/smart-form-validator/dist/smart-form-validator.min.js"></script> <br /> | ||
</head> <br /><br /> | ||
... | ||
<br /><br /> | ||
<form id="test-form"> <br /> | ||
<input type="text" id="name-field" /> <br /> | ||
<input type="email" id="email-field" /> <br /> | ||
<button id="submit-form-button" role="submit-button">Submit Form</button> <br /> | ||
</form> <br /><br /> | ||
|
||
<script type="text/javascript"> <br /> | ||
const form = document.getElementById("test-form"); <br /> | ||
const name = document.getElementById("name-field"); <br /> | ||
const email = document.getElementById("email-field"); <br /><br /> | ||
|
||
// When a form has an `<input type="submit" or <br /> | ||
// an element with `role="submit-button", <br /> | ||
// adding the submit button via `addField()` is optional. <br /> | ||
new SmartFormValidator() <br /> | ||
.addForm(form) <br /> | ||
.addRule({ field: name, length: { min: 3, max: 5 } }) <br /> | ||
.addRule({ field: "email-field", type: "email" }) <br /> | ||
.watch(); <br /> | ||
</script> | ||
</code> | ||
<br /><br /> | ||
</body> | ||
</html> |
Oops, something went wrong.