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
b80c9fcf
authored
2014-03-20 12:33:13 -0500
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Segmented out from main source
1 parent
cb96b40a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
rivets-error-binder.js
rivets-error-binder.js
0 → 100644
View file @
b80c9fc
define
([
'rivets'
],
function
(
rivets
)
{
rivets
.
binders
[
'error-*'
]
=
{
bind
:
function
(
el
)
{
var
self
=
this
;
var
holder
=
this
.
validationHolder
=
{
marker
:
el
.
parentNode
.
insertBefore
(
document
.
createComment
(
" rivets: "
+
this
.
type
+
" "
),
el
),
focus
:
function
()
{
$
(
holder
.
container
).
removeClass
(
'focused'
);
},
blur
:
function
()
{
holder
.
lastObj
.
seen
(
holder
.
lastId
,
true
);
$
(
holder
.
container
).
addClass
(
'focused'
);
holder
.
lastObj
.
validate
();
},
validated
:
function
(
isValid
,
model
,
errors
)
{
var
errorList
=
errors
[
holder
.
lastId
];
var
$container
=
$
(
holder
.
container
);
var
$fieldErrors
=
$container
.
find
(
'> .validationfielderrors'
).
empty
();
if
(
errorList
&&
holder
.
lastObj
.
seen
(
holder
.
lastId
))
{
$container
.
addClass
(
'has-errors'
);
require
([
'text!templates/fielderrorpopup.html!strip'
],
function
(
templateHtml
)
{
$fieldErrors
.
empty
().
append
(
$
(
$
.
parseHTML
(
templateHtml
)).
find
(
'.template-content'
).
append
(
$
.
parseHTML
(
errorList
)).
end
());
});
}
else
{
$container
.
removeClass
(
'has-errors'
);
}
}
};
holder
.
container
=
$
.
parseHTML
(
'<span class="validationerrorcontainer"><div class="validationfielderrors"></div></span>'
);
$
(
holder
.
container
).
removeClass
(
'focused'
);
$
(
holder
.
marker
).
after
(
$
(
holder
.
container
).
append
(
el
));
diveIntoObject
(
this
.
model
,
this
.
keypath
,
function
(
obj
,
id
)
{
holder
.
lastObj
=
obj
;
holder
.
lastId
=
id
;
obj
.
on
(
'validated'
,
holder
.
validated
);
});
$
(
el
).
on
(
'focus'
,
holder
.
focus
).
on
(
'blur'
,
holder
.
blur
);
rivetsBinderCall
(
this
,
this
.
args
[
0
],
'bind'
,
arguments
);
},
unbind
:
function
(
el
)
{
var
holder
=
this
.
validationHolder
;
$
(
this
.
validationHolder
.
marker
).
after
(
el
).
remove
();
$
(
el
).
off
(
'focus'
,
holder
.
focus
).
off
(
'blur'
,
holder
.
blur
);
diveIntoObject
(
this
.
model
,
this
.
keypath
,
function
(
obj
,
id
)
{
obj
.
off
(
'validated'
,
holder
.
validated
);
});
delete
this
.
validationHolder
;
rivetsBinderCall
(
this
,
this
.
args
[
0
],
'unbind'
,
arguments
);
},
routine
:
function
(
el
,
value
)
{
rivetsBinderCall
(
this
,
this
.
args
[
0
],
'routine'
,
arguments
);
}
};
});
Please
register
or
sign in
to post a comment