Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VenJob
Overview
Overview
Details
Activity
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mai Hoang Thai Ha
VenJob
Commits
5ac7cef2
Commit
5ac7cef2
authored
Aug 16, 2021
by
Mai Hoang Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validate FE
parent
fb028337
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
app/javascript/packs/validation.js
+22
-1
app/views/applies/new.html.slim
+5
-2
No files found.
app/javascript/packs/validation.js
View file @
5ac7cef2
...
...
@@ -23,12 +23,32 @@ Validator = function(options) {
errorElement
.
innerText
=
''
inputElement
.
parentElement
.
classList
.
remove
(
'invalid'
)
}
return
!
errorMessage
;
}
// get Element
var
formElement
=
document
.
querySelector
(
options
.
form
)
if
(
formElement
)
{
// handle submit
formElement
.
onsubmit
=
function
(
e
)
{
e
.
preventDefault
();
var
isFormValid
=
true
;
options
.
rules
.
forEach
(
function
(
rule
){
var
inputElement
=
formElement
.
querySelector
(
rule
.
selector
);
var
isValid
=
validate
(
inputElement
,
rule
);
if
(
!
isValid
)
{
isFormValid
=
false
;
}
});
if
(
isFormValid
)
{
formElement
.
submit
()
}
}
options
.
rules
.
forEach
(
function
(
rule
){
// save rules
...
...
@@ -75,4 +95,4 @@ Validator.isEmail = function (selector) {
return
regex
.
test
(
value
)
?
undefined
:
'Email invalid'
;
}
}
}
}
\ No newline at end of file
app/views/applies/new.html.slim
View file @
5ac7cef2
...
...
@@ -22,14 +22,16 @@
.col-10
=
f
.
text_field
:email
,
value:
@apply
.
email
||=
@current_user
.
email
,
class:
'form-control'
span
.form-msg
.row.mb-5
.row.mb-5
.form-group
/ - if @user.cv.attached?
/ = url_for(@user.cv)
.col-2
=
f
.
label
:cv
,
class:
'form-label label'
.col-10
=
f
.
file_field
:cv
,
accept:
ApplyJob
::
ACCEPT_CONTENT_TYPE
,
class:
'form-control'
=
f
.
submit
'Confirm'
,
class:
'btn btn-primary w-25 my-4 btn-height'
span
.form-msg
br
=
f
.
submit
'Confirm'
,
class:
'btn btn-primary w-25 my-4 btn-height'
,
data:
{
disable_with:
false
}
=
render
'validate_form'
javascript:
...
...
@@ -39,6 +41,7 @@ javascript:
rules
:
[
Validator
.
isRequired
(
'#apply_job_user_name'
),
Validator
.
isRequired
(
'#apply_job_email'
),
Validator
.
isRequired
(
'#apply_job_cv'
),
Validator
.
isEmail
(
'#apply_job_email'
)
]
})
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