Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qfq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
typo3
qfq
Commits
8440f826
Commit
8440f826
authored
8 years ago
by
Rafael Ostertag
Browse files
Options
Downloads
Patches
Plain Diff
Added form validation (sort of)
parent
d154c283
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
javascript/src/Form.js
+29
-0
29 additions, 0 deletions
javascript/src/Form.js
javascript/src/QfqForm.js
+39
-3
39 additions, 3 deletions
javascript/src/QfqForm.js
mockup/personmock.html
+9
-5
9 additions, 5 deletions
mockup/personmock.html
with
77 additions
and
8 deletions
javascript/src/Form.js
+
29
−
0
View file @
8440f826
...
...
@@ -92,4 +92,33 @@ var QfqNS = QfqNS || {};
// REMOVE: this.userSubmitFailureHandlers.call(this, textStatus, jqXHR, errorThrown);
};
/**
* @public
* @returns {*}
*/
n
.
Form
.
prototype
.
validate
=
function
()
{
if
(
this
.
$form
.
attr
(
'
novalidate
'
))
{
return
true
;
}
var
formElements
=
document
.
forms
[
this
.
formId
];
var
formElementsLength
=
formElements
.
length
;
var
invalidElements
=
[];
for
(
var
i
=
0
;
i
<
formElementsLength
;
i
++
)
{
var
formElement
=
formElements
[
i
];
if
(
!
formElement
.
willValidate
)
{
continue
;
}
if
(
!
formElement
.
checkValidity
())
{
invalidElements
.
push
(
formElement
);
}
}
return
invalidElements
.
length
===
0
?
true
:
invalidElements
;
};
})(
QfqNS
);
This diff is collapsed.
Click to expand it.
javascript/src/QfqForm.js
+
39
−
3
View file @
8440f826
...
...
@@ -154,6 +154,33 @@ var QfqNS = QfqNS || {};
this
.
eventEmitter
.
emitEvent
(
'
qfqform.destroyed
'
,
n
.
EventEmitter
.
makePayload
(
this
,
null
));
};
n
.
QfqForm
.
prototype
.
checkValidity
=
function
()
{
var
isValid
=
this
.
form
.
validate
();
if
(
isValid
===
true
)
{
return
true
;
}
var
invalidFields
=
isValid
;
this
.
markInvalidFields
(
invalidFields
);
return
false
;
};
n
.
QfqForm
.
prototype
.
markInvalidFields
=
function
(
invalidFields
)
{
var
that
=
this
;
$
.
each
(
invalidFields
,
function
(
index
,
element
)
{
if
(
element
.
hasAttribute
(
'
name
'
))
{
var
elementName
=
element
.
getAttribute
(
'
name
'
);
that
.
setValidationState
(
elementName
,
'
error
'
);
// TODO: Make sure this is portable.
if
(
element
.
validationMessage
)
{
that
.
setHelpBlockValidationMessage
(
elementName
,
element
.
validationMessage
);
}
}
});
};
/**
* @private
*/
...
...
@@ -163,7 +190,7 @@ var QfqNS = QfqNS || {};
// First, remove all validation states, in case a previous submit has set a validation state, thus we're not
// stockpiling them.
this
.
clearAllValidationStates
();
this
.
form
.
submit
To
(
this
.
submitTo
);
this
.
submit
(
);
};
/**
...
...
@@ -175,7 +202,7 @@ var QfqNS = QfqNS || {};
var
alert
=
new
n
.
Alert
(
"
You have unsaved changes. Do you want to close?
"
,
"
warning
"
,
"
yesnosave
"
);
var
that
=
this
;
alert
.
on
(
'
alert.save
'
,
function
()
{
that
.
form
.
submit
To
(
that
.
submitTo
);
that
.
submit
(
);
});
alert
.
on
(
'
alert.ok
'
,
function
()
{
window
.
history
.
back
();
...
...
@@ -186,6 +213,15 @@ var QfqNS = QfqNS || {};
}
};
n
.
QfqForm
.
prototype
.
submit
=
function
()
{
if
(
!
this
.
checkValidity
())
{
var
alert
=
new
n
.
Alert
(
"
Form is incomplete.
"
,
"
warning
"
);
alert
.
show
();
return
;
}
this
.
form
.
submitTo
(
this
.
submitTo
);
};
/**
* @private
*/
...
...
@@ -197,7 +233,7 @@ var QfqNS = QfqNS || {};
var
alert
=
new
n
.
Alert
(
"
You have unsaved changes. Do you want to close?
"
,
"
warning
"
,
"
yesnosave
"
);
var
that
=
this
;
alert
.
on
(
'
alert.save
'
,
function
()
{
that
.
form
.
submit
To
(
that
.
submitTo
);
that
.
submit
(
);
});
alert
.
on
(
'
alert.ok
'
,
function
()
{
var
anchorTarget
=
that
.
getNewButtonTarget
();
...
...
This diff is collapsed.
Click to expand it.
mockup/personmock.html
+
9
−
5
View file @
8440f826
...
...
@@ -123,7 +123,7 @@
</div>
<div
class=
"col-md-6"
>
<input
id=
"name"
type=
"text"
class=
"form-control"
>
<input
id=
"name"
name=
"name"
type=
"text"
class=
"form-control"
>
</div>
</div>
...
...
@@ -134,7 +134,7 @@
</div>
<div
class=
"col-md-6"
>
<input
id=
"firstname"
type=
"text"
class=
"form-control"
>
<input
id=
"firstname"
name=
"firstname"
type=
"text"
class=
"form-control"
>
</div>
</div>
...
...
@@ -143,7 +143,7 @@
<label
for=
"nameShort"
class=
"control-label"
>
Vorname Kurz
</label>
</div>
<div
class=
"col-md-6"
>
<input
id=
"nameShort"
type=
"text"
class=
"form-control"
>
<input
id=
"nameShort"
name=
"shortname"
type=
"text"
class=
"form-control"
>
</div>
<div
class=
"col-md-4"
>
...
...
@@ -156,7 +156,7 @@
<label
for=
"personHandle"
class=
"control-label"
>
Kurzform
</label>
</div>
<div
class=
"col-md-6"
>
<input
id=
"personHandle"
type=
"text"
class=
"form-control"
>
<input
id=
"personHandle"
name=
"personhandle"
type=
"text"
class=
"form-control"
>
</div>
<div
class=
"col-md-4"
>
...
...
@@ -170,7 +170,7 @@
<label
for=
"personTitle"
class=
"control-label"
>
Titel
</label>
</div>
<div
class=
"col-md-6"
>
<select
id=
"personTitle"
class=
"form-control"
>
<select
id=
"personTitle"
class=
"form-control"
name=
"persontitle"
>
<option></option>
<option>
Dr.
</option>
<option>
Prof. Dr.
</option>
...
...
@@ -1013,6 +1013,10 @@
qfqPage
.
qfqForm
.
fileUploader
.
targetUrl
=
'
api/
'
+
$
(
evt
.
target
).
val
();
});
$
(
'
#myForm
'
).
on
(
'
invalid
'
,
function
()
{
console
.
log
(
"
Invalid event catched
"
);
});
QfqNS
.
Log
.
level
=
0
;
});
</script>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment