Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ots
hypha
Commits
2fd77faa
Commit
2fd77faa
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Add Front end validation to the required fields based on Drupal Example
parent
9832bb26
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/funds/static/address_form.js
+49
-3
49 additions, 3 deletions
opentech/apply/funds/static/address_form.js
opentech/apply/funds/widgets.py
+2
-1
2 additions, 1 deletion
opentech/apply/funds/widgets.py
with
51 additions
and
4 deletions
opentech/apply/funds/static/address_form.js
+
49
−
3
View file @
2fd77faa
(
function
(
$
)
{
(
function
(
$
)
{
// add the require attribute to the field configs
function
addRequiredToKey
(
fields
,
findKey
){
$
.
each
(
fields
,
(
index
,
value
)
=>
{
var
fieldName
=
Object
.
keys
(
value
)[
0
];
var
data
=
value
[
fieldName
];
if
(
fieldName
===
findKey
)
{
data
.
required
=
true
;
}
else
if
(
Array
.
isArray
(
data
))
{
// Handle nested fields
addRequiredToKey
(
data
,
findKey
);
}
});
}
// hook into the transform to update with the required attribute
var
oldTransform
=
$
.
fn
.
addressfield
.
transform
;
var
oldTransform
=
$
.
fn
.
addressfield
.
transform
;
$
.
fn
.
addressfield
.
transform
=
function
(
data
)
{
$
.
fn
.
addressfield
.
transform
=
function
(
data
)
{
var
mappedData
=
oldTransform
.
call
(
this
,
data
);
var
mappedData
=
oldTransform
.
call
(
this
,
data
);
$
.
each
(
mappedData
,
(
key
,
value
)
=>
{
$
.
each
(
value
.
required
,
(
index
,
field
)
=>
{
addRequiredToKey
(
mappedData
[
key
].
fields
,
field
);
});
});
return
mappedData
;
return
mappedData
;
};
};
$
(
'
.form
'
).
bind
(
'
addressfield:after
'
,
function
(
e
,
data
)
{
function
labelFor
(
field
){
debugger
;
return
$
(
'
label[for="
'
+
$
(
field
).
attr
(
'
id
'
)
+
'
"]
'
);
});
}
function
makeFieldNotRequired
(
field
){
var
$field
=
$
(
field
);
$
(
this
).
prop
(
'
required
'
,
false
);
var
$label
=
labelFor
(
$field
);
$label
.
children
(
'
span
'
).
remove
();
}
function
makeFieldRequired
(
field
){
var
$field
=
$
(
field
);
$field
.
prop
(
'
required
'
,
true
);
var
$label
=
labelFor
(
$field
);
$label
.
append
(
'
<span class="form__required">*</span>
'
);
}
// Hook into the validate process to update the required display
var
oldValidate
=
$
.
fn
.
addressfield
.
validate
;
$
.
fn
.
addressfield
.
validate
=
function
(
field
,
config
)
{
if
(
config
.
required
)
{
makeFieldRequired
(
this
);
}
else
{
makeFieldNotRequired
(
this
);
}
oldValidate
.
call
(
this
,
field
,
config
);
};
$
(
document
).
ready
(
function
formReady
()
{
$
(
document
).
ready
(
function
formReady
()
{
$
(
'
.form div.address
'
).
addressfield
({
$
(
'
.form div.address
'
).
addressfield
({
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/funds/widgets.py
+
2
−
1
View file @
2fd77faa
...
@@ -60,7 +60,8 @@ class AddressWidget(NestedMultiWidget):
...
@@ -60,7 +60,8 @@ class AddressWidget(NestedMultiWidget):
class
Media
:
class
Media
:
js
=
(
js
=
(
'
jquery.addressfield.min.js
'
,
'
https://cdn.jsdelivr.net/npm/jquery.addressfield@1.1.0/dist/jquery.addressfield.js
'
,
# 'jquery.addressfield.min.js',
'
address_form.js
'
,
'
address_form.js
'
,
)
)
...
...
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