Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
baa946e8
Commit
baa946e8
authored
Jul 21, 2014
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP Form validation on blur
parent
26308d1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
directives.coffee
h/static/scripts/directives.coffee
+27
-0
forms.scss
h/static/styles/forms.scss
+10
-0
No files found.
h/static/scripts/directives.coffee
View file @
baa946e8
...
@@ -439,6 +439,32 @@ whenscrolled = ['$window', ($window) ->
...
@@ -439,6 +439,32 @@ whenscrolled = ['$window', ($window) ->
scope
.
$apply
attr
.
whenscrolled
scope
.
$apply
attr
.
whenscrolled
]
]
validateForm
=
[
'$parse'
,
(
$parse
)
->
require
:
'form'
,
link
:
(
scope
,
elem
,
attr
,
formController
)
->
onSuccess
=
$parse
(
attr
.
validateForm
)
touchedInputs
=
{}
# Inputs that the user has blurred.
scope
.
isFieldValid
=
(
fieldName
)
->
field
=
formController
[
fieldName
]
unless
field
throw
new
Error
(
"The
#{
field
}
field could not be found on this form"
)
touchedInputs
[
fieldName
]
&&
field
.
$dirty
&&
field
.
$invalid
scope
.
fieldClass
=
(
fieldName
,
defaults
,
error
)
->
if
scope
.
isFieldValid
(
fieldName
)
then
"
#{
defaults
}
#{
error
}
"
else
defaults
elem
.
on
'submit'
,
(
event
)
->
Object
.
keys
(
formController
).
forEach
(
prop
)
->
if
prop
.
indexOf
(
'$'
)
!=
0
formController
[
prop
].
$dirty
=
true
touchedInputs
[
prop
]
=
true
elem
.
on
'blur'
,
':input'
,
->
touchedInputs
[
this
.
name
]
=
true
scope
.
$apply
()
]
angular
.
module
(
'h.directives'
,
[
'ngSanitize'
])
angular
.
module
(
'h.directives'
,
[
'ngSanitize'
])
.
directive
(
'fuzzytime'
,
fuzzytime
)
.
directive
(
'fuzzytime'
,
fuzzytime
)
.
directive
(
'markdown'
,
markdown
)
.
directive
(
'markdown'
,
markdown
)
...
@@ -453,3 +479,4 @@ angular.module('h.directives', ['ngSanitize'])
...
@@ -453,3 +479,4 @@ angular.module('h.directives', ['ngSanitize'])
.
directive
(
'repeatAnim'
,
repeatAnim
)
.
directive
(
'repeatAnim'
,
repeatAnim
)
.
directive
(
'visualSearch'
,
visualSearch
)
.
directive
(
'visualSearch'
,
visualSearch
)
.
directive
(
'whenscrolled'
,
whenscrolled
)
.
directive
(
'whenscrolled'
,
whenscrolled
)
.
directive
(
'validateForm'
,
validateForm
)
h/static/styles/forms.scss
View file @
baa946e8
...
@@ -86,6 +86,16 @@
...
@@ -86,6 +86,16 @@
margin-top
:
5px
;
margin-top
:
5px
;
}
}
.form-field
{
&
.form-error-list
{
display
:
none
;
}
&
.form-field-errors
.form-error-list
{
display
:
block
;
}
}
.form-error
{
.form-error
{
font-size
:
13px
;
font-size
:
13px
;
line-height
:
1
.5
;
line-height
:
1
.5
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment