Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
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
david Chavalarias
clinicaltrials
Commits
dc690f38
Commit
dc690f38
authored
Nov 30, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make validation occur *before* doors registration!
parent
ddc64b35
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
117 deletions
+128
-117
comex_reg_form_controllers.js
static/js/comex_reg_form_controllers.js
+126
-115
base_form.html
templates/base_form.html
+2
-2
No files found.
static/js/comex_reg_form_controllers.js
View file @
dc690f38
...
@@ -79,16 +79,16 @@ var passStatus = false
...
@@ -79,16 +79,16 @@ var passStatus = false
var
emailStatus
=
false
var
emailStatus
=
false
var
captchaStatus
=
false
var
captchaStatus
=
false
submitButton
.
disabled
=
true
submitButton
.
disabled
=
true
theForm
.
onkeyup
=
beTested
AsYouGo
theForm
.
onkeyup
=
test
AsYouGo
theForm
.
onchange
=
beTested
AsYouGo
theForm
.
onchange
=
test
AsYouGo
theForm
.
onblur
=
beTested
AsYouGo
theForm
.
onblur
=
test
AsYouGo
var
lastEmailValueCheckedDisplayed
=
null
var
lastEmailValueCheckedDisplayed
=
null
// done when anything in the form changes
// done when anything in the form changes
function
beTested
AsYouGo
()
{
function
test
AsYouGo
()
{
// console.log("
beTested
AsYouGo Go")
// console.log("
test
AsYouGo Go")
if
(
email
.
value
!=
lastEmailValueCheckedDisplayed
)
{
if
(
email
.
value
!=
lastEmailValueCheckedDisplayed
)
{
// will update the emailStatus boolean
// will update the emailStatus boolean
...
@@ -133,33 +133,54 @@ function testDoorsUserExists(emailValue) {
...
@@ -133,33 +133,54 @@ function testDoorsUserExists(emailValue) {
}
}
function
registerDoorsAndSubmit
(
e
){
function
registerDoorsAndSubmit
(){
e
.
preventDefault
()
// ? not necessary if button type is set and != "submit"
submitButton
.
disabled
=
true
mainMessage
.
style
.
display
=
'block'
mainMessage
.
innerHTML
=
"Registering with ISCPIF Doors..."
mainMessage
.
innerHTML
=
"Registering with ISCPIF Doors..."
// objectify the form
// all values from the form have now been validated
wholeFormData
=
new
FormData
(
theForm
);
var
emailValue
=
email
.
value
var
passValue
=
pass1
.
value
var
wholenameValue
=
""
if
(
mName
.
value
!=
""
)
{
wholenameValue
=
lName
.
value
+
', '
+
fName
.
value
+
' '
+
mName
.
value
}
else
{
wholenameValue
=
lName
.
value
+
', '
+
fName
.
value
}
// KNOCKING ON THE DOORS -------------------------------------
// KNOCKING ON THE DOORS -------------------------------------
// /!\ async
// /!\ async
callDoors
(
callDoors
(
"register"
,
"register"
,
[
[
emailValue
,
passValue
,
wholenameValue
],
// these values from the form have been checked by beTestedAsYouGo
wholeFormData
.
get
(
"email"
),
// callback: send to DB -------------------
wholeFormData
.
get
(
"password"
),
wholeFormData
.
get
(
"initials"
)
],
// VALIDATING + send to DB -------------------
function
(
doorsResp
)
{
function
(
doorsResp
)
{
validateSubmit
(
wholeFormData
,
doorsResp
)
addUidThenSubmit
(
doorsResp
)
}
}
)
)
}
function
addUidThenSubmit
(
doorsResp
)
{
var
doorsUid
=
doorsResp
[
0
]
var
doorsMsg
=
doorsResp
[
1
]
if
(
doorsUid
==
null
)
{
mainMessage
.
innerHTML
=
"Problem with doors registration... TODO debug"
mainMessage
.
style
.
color
=
colorRed
submitButton
.
disabled
=
false
}
else
{
// fill in the answer we got
uidInput
.
value
=
doorsUid
console
.
info
(
"form was validated and registered@doors: submitting now"
)
//==== SEND! ====
theForm
.
submit
()
//===============
}
}
}
var
doorsIcon
=
document
.
getElementById
(
'doors_ret_icon'
)
var
doorsIcon
=
document
.
getElementById
(
'doors_ret_icon'
)
...
@@ -180,8 +201,8 @@ function displayDoorsStatusInLoginBox (available, emailValue) {
...
@@ -180,8 +201,8 @@ function displayDoorsStatusInLoginBox (available, emailValue) {
doorsIcon
.
style
.
color
=
colorRed
doorsIcon
.
style
.
color
=
colorRed
}
}
// to debounce further actions in
beTested
AsYouGo
// to debounce further actions in
test
AsYouGo
// return to neutral is also in
beTested
AsYouGo
// return to neutral is also in
test
AsYouGo
lastEmailValueCheckedDisplayed
=
emailValue
lastEmailValueCheckedDisplayed
=
emailValue
}
}
...
@@ -326,44 +347,36 @@ function callDoors(apiAction, data, callback) {
...
@@ -326,44 +347,36 @@ function callDoors(apiAction, data, callback) {
function
makeRandomString
(
nChars
)
{
function
makeRandomString
(
nChars
)
{
var
rando
=
""
var
rando
=
""
var
possible
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
var
possible
=
"abcdefghijklmnopqrstuvwxyz0123456789"
;
var
len
=
possible
.
length
for
(
var
i
=
0
;
i
<
nChars
;
i
++
)
for
(
var
i
=
0
;
i
<
nChars
;
i
++
)
rando
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
possible
.
length
));
rando
+=
possible
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
len
));
return
rando
return
rando
}
}
// doValidate() : actions to do after doors registration and before send
// validateAndMsg() : bool (validates fields before doors registration and send)
// -----------------------------------------------------------------------------
// valid => return *true* which will trigger the doors registration
// and the real submit action
//
//
// => validate the columns
// else => message the user, unblock the button and return *false*
// valid => trigger the real submit action
// -----------------------------------------------------------------------------
// else => message the user & unblock the button
function
validateAndMsg
()
{
// validate more precisely at the end
function
validateSubmit
(
wholeFormData
,
doorsResp
)
{
var
valid
=
true
// not necessary b/c button type is set and is != "submit"
// submitEvent.preventDefault()
// TODO pass mainMessage ref as arg
submitButton
.
disabled
=
true
mainMessage
.
innerHTML
=
"Validating the form..."
mainMessage
.
style
.
display
=
'block'
//
ersatz for tests
//
objectify the form
// doorsUid = makeRandomString(36)
wholeFormData
=
new
FormData
(
theForm
);
var
doorsUid
=
doorsResp
[
0
]
var
valid
=
true
var
doorsMsg
=
doorsResp
[
1
]
if
(
doorsUid
==
null
)
{
// TODO pass mainMessage ref as arg
// TODO harmonize this case with the valid=False case
mainMessage
.
innerHTML
=
"Validating the form..."
mainMessage
.
innerHTML
=
"Problem with doors registration... TODO debug"
mainMessage
.
style
.
color
=
colorRed
submitButton
.
disabled
=
false
}
else
{
// fill in the answer we got
wholeFormData
.
set
(
"doors_uid"
,
doorsUid
)
uidInput
.
value
=
doorsUid
// todo feels redundant (but if we submit via ajax, cgi-bin response won't be loaded)
// here entire validation
var
missingFields
=
[]
var
missingFields
=
[]
var
toolongFields
=
[]
var
toolongFields
=
[]
for
(
var
i
in
COLS
)
{
for
(
var
i
in
COLS
)
{
...
@@ -377,6 +390,9 @@ function validateSubmit(wholeFormData, doorsResp) {
...
@@ -377,6 +390,9 @@ function validateSubmit(wholeFormData, doorsResp) {
// skip picture already done
// skip picture already done
if
(
fieldName
==
'pic_file'
)
continue
;
if
(
fieldName
==
'pic_file'
)
continue
;
// skip doors_uid done afterwards if form ok
if
(
fieldName
==
'doors_uid'
)
continue
;
var
actualValue
=
wholeFormData
.
get
(
fieldName
)
var
actualValue
=
wholeFormData
.
get
(
fieldName
)
// console.log("actualValue", actualValue)
// console.log("actualValue", actualValue)
...
@@ -421,13 +437,9 @@ function validateSubmit(wholeFormData, doorsResp) {
...
@@ -421,13 +437,9 @@ function validateSubmit(wholeFormData, doorsResp) {
// add the captchaCheck inside the form (jquery interference)
// add the captchaCheck inside the form (jquery interference)
captchaCheck
.
value
=
$
(
captcha
).
realperson
(
'getHash'
)
captchaCheck
.
value
=
$
(
captcha
).
realperson
(
'getHash'
)
mainMessage
.
innerHTML
=
"Form is valid... Submitting
..."
mainMessage
.
innerHTML
=
"Form is valid... Will register and submit
..."
mainMessage
.
style
.
display
=
'block'
mainMessage
.
style
.
display
=
'block'
// console.log("uidInput.value", uidInput.value)
theForm
.
submit
()
// debug
console
.
log
(
"submitted"
)
return
true
return
true
}
}
else
{
else
{
...
@@ -447,8 +459,6 @@ function validateSubmit(wholeFormData, doorsResp) {
...
@@ -447,8 +459,6 @@ function validateSubmit(wholeFormData, doorsResp) {
mainMessage
.
innerHTML
=
errorMessage
mainMessage
.
innerHTML
=
errorMessage
return
false
return
false
}
}
}
console
.
warn
(
"=====> end of doValidate <====="
)
}
}
...
@@ -625,16 +635,17 @@ var passwords = [pass1, pass2]
...
@@ -625,16 +635,17 @@ var passwords = [pass1, pass2]
// £DEBUG autofill ----------->8------
// £DEBUG autofill ----------->8------
// f
irst_n
ame.value = "Jean"
// f
N
ame.value = "Jean"
// l
ast_n
ame.value = "Tartampion"
// l
N
ame.value = "Tartampion"
// initialsInput.value="JPP"
// initialsInput.value="JPP"
// document.getElementById('country').value = "France"
// document.getElementById('country').value = "France"
// email.value= makeRandomString(
10
)+"@om.fr"
// email.value= makeRandomString(
7
)+"@om.fr"
// pass1.value="123456+789"
// pass1.value="123456+789"
// pass2.value="123456+789"
// pass2.value="123456+789"
// document.getElementById('jobtitle').value = "atitle"
// document.getElementById('jobtitle').value = "atitle"
// document.getElementById('keywords').value = "Blabla"
// document.getElementById('keywords').value = "Blabla"
// document.getElementById('institution').value = "CNRS"
// document.getElementById('institution').value = "CNRS"
// basicEmailValidate(email.value)
// --------------------------->8------
// --------------------------->8------
...
...
templates/base_form.html
View file @
dc690f38
...
@@ -76,7 +76,7 @@
...
@@ -76,7 +76,7 @@
<!-- ########################### ( FORM ) ########################## -->
<!-- ########################### ( FORM ) ########################## -->
<form
id=
"comex_reg_form"
enctype=
"multipart/form-data"
<form
id=
"comex_reg_form"
enctype=
"multipart/form-data"
method=
"post"
onsubmit=
"
validateSubmit(event, 'from form', 'register
')"
>
method=
"post"
onsubmit=
"
console.info('submitted
')"
>
<!-- todo onsubmit also save to cache -->
<!-- todo onsubmit also save to cache -->
...
@@ -400,7 +400,7 @@
...
@@ -400,7 +400,7 @@
<!-- also remember stackoverflow.com/a/3315016/2489184 -->
<!-- also remember stackoverflow.com/a/3315016/2489184 -->
<button
class=
"btn btn-lg btn-success"
style=
"float:right"
<button
class=
"btn btn-lg btn-success"
style=
"float:right"
id=
"formsubmit"
type=
button
id=
"formsubmit"
type=
button
onclick=
"
registerDoorsAndSubmit(event)
"
>
onclick=
"
if (validateAndMsg(event)) {registerDoorsAndSubmit()}
"
>
Submit your form
Submit your form
</button>
</button>
...
...
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