Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web-ui
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WEBGDE-Components
web-ui
Commits
50961daf
Commit
50961daf
authored
Jul 12, 2023
by
Owen Ryan Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed logic for clearing fields and for repopulating fields.
parent
b1ba2a3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
21 deletions
+45
-21
generateFields.js
...bContent/WebGde-Widgets/DataInputWidget/generateFields.js
+45
-21
No files found.
WebGde/WebContent/WebGde-Widgets/DataInputWidget/generateFields.js
View file @
50961daf
...
...
@@ -121,34 +121,30 @@ export async function generateFields(inputSchema, containerId) {
}
$
(
document
.
body
).
on
(
"change"
,
"#DocType"
,
async
function
()
{
console
.
log
(
"change"
)
const
elements
=
document
.
getElementsByClassName
(
sessionStorage
.
getItem
(
"currentSection"
));
while
(
elements
.
length
>
0
)
{
elements
[
0
].
parentNode
.
removeChild
(
elements
[
0
]);
}
const
secElements
=
document
.
getElementsByClassName
(
sessionStorage
.
getItem
(
"currentDoctype"
));
while
(
secElements
.
length
>
0
)
{
secElements
[
0
].
parentNode
.
removeChild
(
secElements
[
0
]);
}
let
doctypes
=
schema
[
this
.
value
];
let
underscoredValue
=
this
.
value
.
replaceAll
(
" "
,
"_"
);
sessionStorage
.
setItem
(
"currentDoctype"
,
underscoredValue
);
const
{
valid
,
error
}
=
validateSchema
()
const
{
valid
,
error
}
=
validateSchema
();
if
(
!
valid
)
{
container
.
textContent
=
error
container
.
style
.
color
=
'#ff3333'
container
.
textContent
=
error
;
container
.
style
.
color
=
'#ff3333'
;
}
for
(
let
key
in
doctypes
)
{
let
underscoredKey
=
key
.
replaceAll
(
" "
,
"_"
);
sessionStorage
.
setItem
(
"currentSection"
,
underscoredKey
);
createSection
(
'Section'
,
container
,
doctypes
,
underscoredValue
);
container
=
await
deconstruct
(
doctypes
[
key
],
container
,
underscoredKey
)
container
=
await
deconstruct
(
doctypes
[
key
],
container
,
underscoredKey
)
;
// const submit = document.createElement('input')
// submit.classList.add("submitButtons");
// submit.classList.add(underscoredKey);
...
...
@@ -156,7 +152,7 @@ export async function generateFields(inputSchema, containerId) {
// container.appendChild(submit)
break
;
}
});
});
$
(
document
.
body
).
on
(
"change"
,
"#Section"
,
async
function
()
{
const
elements
=
document
.
getElementsByClassName
(
sessionStorage
.
getItem
(
"currentSection"
));
...
...
@@ -670,16 +666,23 @@ const createDocTypeDropdown = (fieldLabel, container, schema, doc) => {
docTypeDropDown
.
classList
.
add
(
'dropdown-input'
)
// docTypeDropDown.addEventListener('focusout', handleInput)
let
defaultOptionSelected
=
false
;
// Track if a matching option is found
for
(
const
doctype
in
schema
)
{
newOption
=
document
.
createElement
(
"option"
)
newOption
.
text
=
doctype
newOption
.
value
=
doctype
if
(
doctype
==
doc
)
{
newOption
.
selected
=
'selected'
defaultOptionSelected
=
true
}
docTypeDropDown
.
add
(
newOption
)
}
if
(
!
defaultOptionSelected
)
{
docTypeDropDown
.
selectedIndex
=
0
;
// Set the first option as selected by default
}
docTypeDropDown
.
classList
.
add
(
'inputField'
)
inputContainer
.
appendChild
(
docTypeDropDown
)
...
...
@@ -810,7 +813,7 @@ export async function populateFields(imagePath) {
return
;
}
if
(
resp
[
0
]
!=
null
)
{
if
(
resp
[
0
]
!=
null
&&
'DocType'
in
resp
[
0
]
)
{
var
doctype
=
resp
[
0
].
DocType
;
var
section
=
resp
[
0
].
Section
;
saveXMLToStorage
(
parseInt
(
sessionStorage
.
getItem
(
"display_counter"
)),
resp
[
0
].
fields
);
...
...
@@ -893,12 +896,32 @@ export async function populateFields(imagePath) {
}
export
function
clearForm
()
{
// Check if the form element exists
const
formElement
=
document
.
getElementById
(
"fields"
);
if
(
formElement
)
{
// Clear the form by resetting its fields
formElement
.
reset
();
}
else
{
console
.
log
(
"Form element not found"
);
}
// Check if the form element exists
const
formElement
=
document
.
getElementById
(
"fields"
);
if
(
formElement
)
{
// Retain the selected 'doctype'
const
docTypeField
=
formElement
.
querySelector
(
'#DocType'
);
const
doctype
=
docTypeField
.
value
||
docTypeField
.
options
[
docTypeField
.
selectedIndex
].
value
;
// Clear the form by resetting its fields
formElement
.
reset
();
// Set the selected 'doctype' back
const
options
=
docTypeField
.
options
;
const
{
elements
}
=
formElement
for
(
let
i
=
0
;
i
<
options
.
length
;
i
++
)
{
if
(
options
[
i
].
value
===
doctype
)
{
for
(
let
element
of
elements
)
{
const
{
id
}
=
element
if
(
id
===
'DocType'
)
{
element
.
selectedIndex
=
i
}
}
}
}
}
else
{
console
.
log
(
"Form element not found"
);
}
}
\ No newline at end of file
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