Commit 086f470b authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Removed InputMatcher.js. Is already provided by bootstrap-validator.

parent 6b133e18
......@@ -8,7 +8,6 @@ module.exports = function (grunt) {
var js_sources = [
'javascript/src/Helper/*.js',
'javascript/src/Element/*.js',
'javascript/src/Validation/*.js',
'javascript/src/*.js'
];
......
......@@ -38,7 +38,6 @@ var QfqNS = QfqNS || {};
this.fileDeleteUrl = fileDeleteUrl;
this.form = new n.Form(this.formId);
this.inputMatcher = new n.Validation.InputMatcher(this.formId);
// This is required when displaying validation messages, in to activate the tab, which has validation issues
this.bsTabs = null;
this.lastButtonPress = null;
......@@ -355,11 +354,6 @@ var QfqNS = QfqNS || {};
n.QfqForm.prototype.submit = function () {
var alert;
if (this.inputMatcher.validate() !== true) {
alert = new n.Alert("Form is incomplete.", "warning");
alert.show();
return;
}
if (this.form.validate() !== true) {
var element = this.form.getFirstNonValidElement();
......
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* global $ */
/* @depend ../Element/FormGroup.js */
/**
* Qfq Namespace
*
* @namespace QfqNS
*/
var QfqNS = QfqNS || {};
/**
* Qfq.Element Namespace
*
* @namespace QfqNS.Element
*/
QfqNS.Validation = QfqNS.Validation || {};
(function (n) {
'use strict';
function InputMatcher(formId) {
this.formId = formId;
this.list = [];
this.addAllElementsToList();
}
/**
* @private
*/
InputMatcher.prototype.addAllElementsToList = function () {
var $requireMatching = this.findElementsRequireMatchingOnForm();
var that = this;
$requireMatching.each(function (index, element) {
var $element = $(element);
var $slave = that.resolveCompareElements($element);
if (!$slave) {
return;
}
var masterFormGroup = that.convertElementToFormGroup($element);
var slaveFormGroup = that.convertElementToFormGroup($slave);
that.list.push({
master: masterFormGroup,
slave: slaveFormGroup
});
});
};
/**
* @private
*/
InputMatcher.prototype.findElementsRequireMatchingOnForm = function () {
return this.findOnForm('[data-compare-element]');
};
/**
* @private
*/
InputMatcher.prototype.findOnForm = function (selector) {
return $('#' + this.formId).find(selector);
};
/**
* @private
*/
InputMatcher.prototype.resolveCompareElements = function ($element) {
var $slave;
var slaveName = $element.data('compare-element');
if (!slaveName) {
return null;
}
$slave = this.findOnForm('[name=' + QfqNS.escapeJqueryIdSelector(slaveName) + ']');
if ($slave.length === 0) {
return null;
}
return $($slave[0]);
};
/**
* @private
*/
InputMatcher.prototype.convertElementToFormGroup = function ($element) {
//return new QfqNS.Element.FormGroup($element);
return QfqNS.Element.getElement($element.attr('name'));
};
InputMatcher.prototype.validate = function () {
var length = this.list.length;
var valid = true;
for (var i = 0; i < length; i++) {
var matcher = this.list[i];
if (matcher.master.getValue() !== matcher.slave.getValue()) {
matcher.slave.setError(true);
matcher.slave.setHelp("Does not match");
valid = false;
} else {
matcher.slave.setError(false);
matcher.slave.clearHelp();
}
}
return valid;
};
n.InputMatcher = InputMatcher;
})(QfqNS.Validation);
\ No newline at end of file
......@@ -15,8 +15,6 @@
</head>
<body>
<button id="validateMatchers">Validate</button>
<label>Submit to
<select name="submitTo" id="submitTo">
<option>404 error</option>
......@@ -84,8 +82,7 @@
<div class='col-md-6'><input type="email" class="form-control" id="personEmail" name="personEmail"
placeholder="Email"
title="Tooltip"
data-toggle="tooltip" data-placement="right"
data-compare-element="personEmailRETYPE"></div>
data-toggle="tooltip" data-placement="right"></div>
<div class="help-block">Email of the person.</div>
</div>
......@@ -98,8 +95,8 @@
<input type="email" class="form-control" id="personEmailRETYPE"
name="personEmailRETYPE"
placeholder="Email" title="Tooltip"
data-toggle="tooltip" data-placement="right"></div>
<div class="help-block"></div>
data-toggle="tooltip" data-placement="right" data-match="#personEmail"></div>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
......@@ -108,7 +105,7 @@
placeholder="Email"
title="Tooltip"
data-toggle="tooltip" data-placement="right"
data-compare-element="personEmail2RETYPE"></div>
></div>
<div class="help-block">Email of the person.</div>
</div>
......@@ -121,8 +118,9 @@
<input type="email" class="form-control" id="personEmail2RETYPE"
name="personEmail2RETYPE"
placeholder="Email" title="Tooltip"
data-toggle="tooltip" data-placement="right"></div>
<div class="help-block"></div>
data-toggle="tooltip" data-placement="right"
data-match="[name=personEmail2]"></div>
<div class="help-block with-errors"></div>
</div>
</form>
......@@ -169,15 +167,6 @@
console.log("Invalid event catched");
});
$('#validateMatchers').on("click", function () {
var inputMatcher = new QfqNS.Validation.InputMatcher("myForm");
if (!inputMatcher.validate()) {
console.log("Invalid");
} else {
console.log("Valid");
}
});
QfqNS.Log.level = 0;
});
......
......@@ -147,25 +147,6 @@
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="form-group">
<label for="personEmail2">Email2</label>
<input type="email" class="form-control" id="personEmail2" name="personEmail2" placeholder="Email"
title="Tooltip"
data-toggle="tooltip" data-placement="right" data-compare-element="personEmail2RETYPE">
<p class="help-block">Email of the person.</p>
</div>
<div class="form-group">
<label for="personEmail2RETYPE">please retype</label>
<input type="email" class="form-control" id="personEmail2RETYPE" name="personEmail2RETYPE"
placeholder="Email" title="Tooltip"
data-toggle="tooltip" data-placement="right">
<p class="help-block"></p>
</div>
</form>
</div>
......@@ -1194,7 +1175,7 @@
// prepare the data
var data = new Array();
var data = [];
var firstNames =
[
"Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment