Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 96 additions & 94 deletions src/demo/index2.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,108 @@
</head>
<body>

<form method="post" id="form2submit" novalidate>
<div>
<label>Only Alpha</label>
<input type="text" data-allow="onlyAlpha" name="name1"
data-message="<b style='color:green'>This field is required.</b>" required>
</div>
<div>
<label>String</label>
<input type="text" data-allow="string" data-message="This also required." data-allowSpecial="+-" name="name2"
required>
</div>
<div>
<label>Pattern</label>
<input type="text" pattern="^[0-5]+$" data-allowSpecial="/-" name="pattern">
</div>
<div>
<label>Number</label>
<input type="number" name="name3" required>
</div>
<div>
<label>Min Validator</label>
<input type="text" name="name4" min="5" max="10" required>
</div>
<div>
<label>Email Validator</label>
<input type="email" name="email" required>
</div>
<div>
<label>Password</label>
<input type="password" name="name5" data-check="repassword" id="password" required>
</div>
<div>
<label>Re-Password</label>
<input type="password" name="name6" data-parent="password" id="repassword" required>
</div>
<div>
<label>From Date</label>
<input type="date" name="dateFrom" required>
</div>
<div>
<label>To Date</label>
<input type="date" name="dateTo" required>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div>
<label></label>
<input type="submit" value="Submit">
</div>
</form>

<div class="col-md-8" align="center" style="margin-left: 20%">
<form method="post" id="form2submit" novalidate>
<div>
<label>Only Alpha</label>
<input type="text" data-allow="onlyAlpha" name="name1"
data-message="<b style='color:green'>This field is required.</b>" required>
</div>
<div>
<label>String</label>
<input type="text" data-allow="string" data-message="This also required." data-allowSpecial="+-"
name="name2"
required>
</div>
<div>
<label>Pattern</label>
<input type="text" pattern="^[0-5]+$" data-allowSpecial="/-" name="pattern">
</div>
<div>
<label>Number</label>
<input type="number" name="name3" required>
</div>
<div>
<label>Min Validator</label>
<input type="text" name="name4" min="5" max="10" required>
</div>
<div>
<label>Email Validator</label>
<input type="email" name="email" required>
</div>
<div>
<label>Password</label>
<input type="password" name="name5" data-check="repassword" id="password" required>
</div>
<div>
<label>Re-Password</label>
<input type="password" name="name6" data-parent="password" id="repassword" required>
</div>
<div>
<label>From Date</label>
<input type="date" name="dateFrom" required>
</div>
<div>
<label>To Date</label>
<input type="date" name="dateTo" required>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div>
<label></label>
<input type="submit" value="Submit">
</div>
</form>
</div>
<!--<script src="./../js/validatorNew.js"></script>-->
<script src="./../js/validatorNew.es6.js"></script>

<script>

var form = new jsValidator().init({
form: 'form2submit',
forceFilter: true,
onChange: true,
message: {
required: 'This field is required 123 !',
min: '<br><span style="color: red;">This field is less then the limit [INDEX]</span>',
max: 'This field is exceeds the limit of [INDEX]',
password: 'Password doesn\'t match !',
email: 'Invalid Email found !'
}
});
var form = new jsValidator().init({
form: 'form2submit',
forceFilter: true,
onChange: true,
message: {
required: 'This field is required 123 !',
min: '<br><span style="color: red;">This field is less then the limit [INDEX]</span>',
max: 'This field is exceeds the limit of [INDEX]',
password: 'Password doesn\'t match !',
email: 'Invalid Email found !'
}
});

// var form = jsValidator.init({
// form: 'form2submit',
// forceFilter: true,
// onChange: true,
// message: {
// required: 'This field is required !',
// min: 'This field is less then the limit [INDEX]',
// max: 'This field is exceeds the limit of [INDEX]',
// password: 'Password doesn\'t match !',
// email: 'Invalid Email found !'
// }
// });
// var form = jsValidator.init({
// form: 'form2submit',
// forceFilter: true,
// onChange: true,
// message: {
// required: 'This field is required !',
// min: 'This field is less then the limit [INDEX]',
// max: 'This field is exceeds the limit of [INDEX]',
// password: 'Password doesn\'t match !',
// email: 'Invalid Email found !'
// }
// });

</script>
</body>
Expand Down
52 changes: 26 additions & 26 deletions src/demo/index3.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,36 @@
<button type="submit" name="btn-save" class="btn btn-default">Submit</button>
</form>
</div>
<script src="./../js/validatorNew.js"></script>
<!--<script src="./../js/validatorNew.es6.js"></script>-->
<!--<script src="./../js/validatorNew.js"></script>-->
<script src="./../js/validatorNew.es6.js"></script>

<script>

// var form = new jsValidator().init({
// form: 'clientAdd',
// forceFilter: true,
// onChange: true,
// message: {
// required: 'This field is required 123 !',
// min: '<br><span style="color: red;">This field is less then the limit [INDEX]</span>',
// max: 'This field is exceeds the limit of [INDEX]',
// password: 'Password doesn\'t match !',
// email: 'Invalid Email found !'
// }
// });
var form = new jsValidator().init({
form: 'clientAdd',
forceFilter: true,
onChange: true,
message: {
required: 'This field is required 123 !',
min: '<br><span style="color: red;">This field is less then the limit [INDEX]</span>',
max: 'This field is exceeds the limit of [INDEX]',
password: 'Password doesn\'t match !',
email: 'Invalid Email found !'
}
});

var form = jsValidator.init({
form: 'clientAdd',
forceFilter: true,
onChange: true,
message: {
required: 'This field is required !',
min: 'This field is less then the limit [INDEX]',
max: 'This field is exceeds the limit of [INDEX]',
password: 'Password doesn\'t match !',
email: 'Invalid Email found !'
}
});
// var form = jsValidator.init({
// form: 'clientAdd',
// forceFilter: true,
// onChange: true,
// message: {
// required: 'This field is required !',
// min: 'This field is less then the limit [INDEX]',
// max: 'This field is exceeds the limit of [INDEX]',
// password: 'Password doesn\'t match !',
// email: 'Invalid Email found !'
// }
// });

</script>
</body>
Expand Down
66 changes: 37 additions & 29 deletions src/js/validatorNew.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,77 +561,85 @@ class jsRuleSets {
let validElem = true;
let firstErrorHit = false;
// To Generally checks, the field is empty or not.
if (!this.isSet(activeElem)) {
log.push({'el': activeElem, 'type': 'required', 'id': activeElem.name});
if (!jsRuleSets.isSet(activeElem)) {
log.push({
'el': activeElem,
'type': 'required',
'id': activeElem.name + Math.random().toString(36).substring(2)
});
if (false == firstErrorHit) firstErrorHit = activeElem;
}
// To Check the Value is less than min or not.
} // To Check the Value is less than min or not.

if (activeElem.min) {
if (this.isSet(activeElem)) {
if (!this.min(activeElem)) {
if (jsRuleSets.isSet(activeElem)) {
if (!jsRuleSets.min(activeElem)) {
log.push({
'el': activeElem,
'type': 'min',
'id': activeElem.name
'id': activeElem.name + Math.random().toString(36).substring(2)
});
if (false == firstErrorHit) firstErrorHit = activeElem;
validElem = false;
}
}
}
// To Check the Value is grater than max or not.
} // To Check the Value is grater than max or not.

if (activeElem.max) {
if (this.isSet(activeElem)) {
if (!this.max(activeElem)) {
if (jsRuleSets.isSet(activeElem)) {
if (!jsRuleSets.max(activeElem)) {
log.push({
'el': activeElem,
'type': 'max',
'id': activeElem.name
'id': activeElem.name + Math.random().toString(36).substring(2)
});
if (false == firstErrorHit) firstErrorHit = activeElem;
validElem = false;
}
}
}
// To Check the Entered E-mail is Valid or Not.
if (activeElem.type == "email") {
if (this.isSet(activeElem)) {
if (!this.email(activeElem)) {
} // To Check the Entered E-mail is Valid or Not.

if (activeElem.type == 'email') {
if (jsRuleSets.isSet(activeElem)) {
if (!jsRuleSets.email(activeElem)) {
log.push({
'el': activeElem,
'type': 'email',
'id': activeElem.name
'id': activeElem.name + Math.random().toString(36).substring(2)
});
if (false == firstErrorHit) firstErrorHit = activeElem;
validElem = false;
}
}
}
// To Compare the Password is Same or Not with Re-Password.
} // To Compare the Password is Same or Not with Re-Password.
// TODO: Implement Simplified Comparison.
if (activeElem.type == "password") {
if (this.isSet(activeElem)) {
if (!this.compare(activeElem)) {

if (activeElem.type == 'password') {
if (jsRuleSets.isSet(activeElem)) {
if (!jsRuleSets.compare(activeElem)) {
log.push({
'el': activeElem,
'type': 'password',
'id': activeElem.name
'id': activeElem.name + Math.random().toString(36).substring(2)
});
if (false == firstErrorHit) firstErrorHit = activeElem;
validElem = false;
}
}
}
// If valid, then reset validation message.
} // If valid, then reset validation message.

if (true === validElem) {
jsLogger.out('Valid Elem', activeElem);
if (activeElem.name !== '') {
let elem = document.getElementById(activeElem.name);
if (typeof(elem) !== 'undefined' && elem !== null) {
var elem = document.getElementById(activeElem.name);
if (typeof (elem) !== 'undefined' && elem !== null) {
elem.innerHTML = '';
}
}
}
if (false !== firstErrorHit) helper.scrollToItem(firstErrorHit);
if (false !== firstErrorHit) {
jsLogger.out('First Hit ', firstErrorHit);
helper.scrollToItem(firstErrorHit);
} // Return overall log report of validation.
// Return overall log report of validation.
return log;
}
Expand Down
Loading