Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets-error-binder
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5a3a0008
authored
2014-04-14 16:40:03 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Move all the html calls into a separate function; eventually, this will
be externalized.
1 parent
8f826811
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
src/scripts/rivets-error-binder.js
src/scripts/rivets-error-binder.js
View file @
5a3a000
...
...
@@ -13,18 +13,37 @@ define(['rivets', 'bootstrap'], function(rivets) {
}
};
var
render
=
function
(
el
,
cmd
,
errorList
)
{
switch
(
cmd
)
{
case
'focus'
:
break
;
case
'blur'
:
break
;
case
'validated'
:
if
(
errorList
)
{
$
(
el
).
tooltip
({
title
:
errorList
,
trigger
:
'focus'
});
$
(
el
).
tooltip
(
'show'
);
$
(
el
).
parent
().
addClass
(
'has-error'
);
}
else
{
$
(
el
).
tooltip
(
'destroy'
);
$
(
el
).
parent
().
removeClass
(
'has-error'
);
}
break
;
}
};
rivets
.
binders
[
'error-*'
]
=
{
bind
:
function
(
el
)
{
var
holder
=
this
.
validationHolder
=
{
//marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
focus
:
function
()
{
$
(
holder
.
container
).
removeClass
(
'focused'
);
render
(
el
,
'focus'
,
false
);
},
blur
:
function
()
{
if
(
holder
.
observer
&&
holder
.
observer
.
target
)
{
holder
.
observer
.
target
.
seen
(
holder
.
observer
.
key
.
path
,
true
);
}
$
(
holder
.
container
).
addClass
(
'focused'
);
render
(
el
,
'blur'
,
false
);
if
(
holder
.
observer
&&
holder
.
observer
.
target
)
{
holder
.
observer
.
target
.
validate
();
}
...
...
@@ -32,12 +51,9 @@ define(['rivets', 'bootstrap'], function(rivets) {
validated
:
function
(
isValid
,
model
,
errors
)
{
var
errorList
=
errors
[
holder
.
observer
.
key
.
path
];
if
(
errorList
&&
holder
.
observer
.
target
&&
holder
.
observer
.
target
.
seen
(
holder
.
observer
.
key
.
path
))
{
$
(
el
).
tooltip
({
title
:
errorList
,
trigger
:
'focus'
});
$
(
el
).
tooltip
(
'show'
);
$
(
el
).
parent
().
addClass
(
'has-error'
);
render
(
el
,
'validated'
,
errorList
);
}
else
{
$
(
el
).
tooltip
(
'destroy'
);
$
(
el
).
parent
().
removeClass
(
'has-error'
);
render
(
el
,
'validated'
,
false
);
}
}
};
...
...
Please
register
or
sign in
to post a comment