Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config to disable setting errors as 'title' #169

Merged
merged 1 commit into from
Nov 25, 2012
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
5 changes: 4 additions & 1 deletion Src/knockout.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
var defaults = {
registerExtenders: true,
messagesOnModified: true,
errorsAsTitle: true, // enables/disables showing of errors as title attribute of the target element.
errorsAsTitleOnModified: false, // shows the error when hovering the input field (decorateElement must be true)
messageTemplate: null,
insertMessages: true, // automatically inserts validation messages as <span></span>
Expand Down Expand Up @@ -781,7 +782,9 @@

//add or remove class on the element;
ko.bindingHandlers.css.update(element, cssSettingsAccessor);


if (!config.errorsAsTitle) return;

var origTitle = element.getAttribute('data-orig-title');
var elementTitle = element.title;
var titleIsErrorMsg = element.getAttribute('data-orig-title') == "true"
Expand Down
34 changes: 34 additions & 0 deletions Tests/validation-ui-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ test('Original titles are restored with multiple validators, too', function () {

});

test('Showing Errors As Titles is disabled sucessfully', function () {

addTestHtml('<input id="myTestInput" data-bind="value: firstName" type="text" />');

var vm = {
firstName: ko.observable('').extend({ required: true })
};

// make sure the options are ok.
ko.validation.init({
errorsAsTitleOnModified: true,
decorateElement: true,
errorsAsTitle: false
}, true);

applyTestBindings(vm);

var $testInput = $('#myTestInput');

$testInput.val("a"); //set it
$testInput.change(); //trigger change event

$testInput.val(""); //set it
$testInput.change(); //trigger change event

var isValid = vm.firstName.isValid();

ok(!isValid, 'First Name is NOT Valid');
console.log($testInput)
var msg = $testInput.attr('title');

notEqual(msg, 'This field is required.', msg);
});

//#endregion

//#region Validation Option Tests
Expand Down