Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MainNet Commitments UI
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
archives
MainNet Commitments UI
Commits
9ffa6498
Commit
9ffa6498
authored
Jul 12, 2022
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix range
parent
e9f16b9c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
form/fileButton.go
+2
-2
2 additions, 2 deletions
form/fileButton.go
form/part.go
+5
-4
5 additions, 4 deletions
form/part.go
form/validate.go
+27
-25
27 additions, 25 deletions
form/validate.go
main.js
+13
-16
13 additions, 16 deletions
main.js
with
47 additions
and
47 deletions
form/fileButton.go
+
2
−
2
View file @
9ffa6498
...
@@ -110,10 +110,10 @@ func (i *FileButton) SetFile(value string) {
...
@@ -110,10 +110,10 @@ func (i *FileButton) SetFile(value string) {
// If validation fails, the error is set as the help text and returns true.
// If validation fails, the error is set as the help text and returns true.
// If validations succeeds, it returns true.
// If validations succeeds, it returns true.
func
(
i
*
FileButton
)
Validate
()
(
interface
{},
bool
)
{
func
(
i
*
FileButton
)
Validate
()
(
interface
{},
bool
)
{
validated
,
err
:=
i
.
v
(
i
.
value
)
validated
,
helpText
,
err
:=
i
.
v
(
i
.
value
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to validate input %+v: %+v"
,
i
.
caption
,
err
)
jww
.
ERROR
.
Printf
(
"Failed to validate input %+v: %+v"
,
i
.
caption
,
err
)
i
.
SetHelpText
(
err
.
Error
()
)
i
.
SetHelpText
(
helpText
)
return
nil
,
false
return
nil
,
false
}
}
...
...
This diff is collapsed.
Click to expand it.
form/part.go
+
5
−
4
View file @
9ffa6498
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
// ValidateFunc is the function used to validate an input value when a form is
// ValidateFunc is the function used to validate an input value when a form is
// submitted. If the validation fails, an error describing why is returned. If
// submitted. If the validation fails, an error describing why is returned. If
// validation succeeds, nil is returned.
// validation succeeds, nil is returned.
type
ValidateFunc
func
(
str
string
)
(
interface
{},
error
)
type
ValidateFunc
func
(
str
string
)
(
interface
{},
string
,
error
)
type
Part
struct
{
type
Part
struct
{
caption
string
caption
string
...
@@ -39,19 +39,20 @@ func (p *Part) ClearHelpText() {
...
@@ -39,19 +39,20 @@ func (p *Part) ClearHelpText() {
func
(
p
*
Part
)
Validate
()
(
interface
{},
bool
)
{
func
(
p
*
Part
)
Validate
()
(
interface
{},
bool
)
{
var
validated
interface
{}
var
validated
interface
{}
var
err
error
var
err
error
var
helpText
string
if
t
,
_
:=
p
.
GetInputAttribute
(
"type"
);
t
==
"checkbox"
{
if
t
,
_
:=
p
.
GetInputAttribute
(
"type"
);
t
==
"checkbox"
{
val
:=
""
val
:=
""
if
p
.
Checked
()
{
if
p
.
Checked
()
{
val
=
"true"
val
=
"true"
}
}
validated
,
err
=
p
.
v
(
val
)
validated
,
helpText
,
err
=
p
.
v
(
val
)
}
else
{
}
else
{
validated
,
err
=
p
.
v
(
p
.
f
.
GetValue
())
validated
,
helpText
,
err
=
p
.
v
(
p
.
f
.
GetValue
())
}
}
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to validate input %q: %+v"
,
p
.
caption
,
err
)
jww
.
ERROR
.
Printf
(
"Failed to validate input %q: %+v"
,
p
.
caption
,
err
)
p
.
SetHelpText
(
err
.
Error
()
)
p
.
SetHelpText
(
helpText
)
return
nil
,
false
return
nil
,
false
}
}
...
...
This diff is collapsed.
Click to expand it.
form/validate.go
+
27
−
25
View file @
9ffa6498
package
form
package
form
import
(
import
(
"fmt"
"github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/xx-labs/sleeve/wallet"
"github.com/xx-labs/sleeve/wallet"
"gitlab.com/xx_network/primitives/id/idf"
"gitlab.com/xx_network/primitives/id/idf"
...
@@ -11,89 +12,90 @@ import (
...
@@ -11,89 +12,90 @@ import (
// ValidateXXNetworkAddress returns an error if the xx network address is
// ValidateXXNetworkAddress returns an error if the xx network address is
// invalid. This function adheres to the ValidateFunc type.
// invalid. This function adheres to the ValidateFunc type.
func
ValidateXXNetworkAddress
(
str
string
)
(
interface
{},
error
)
{
func
ValidateXXNetworkAddress
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
{
return
nil
,
errors
.
New
(
"Required
.
"
)
return
nil
,
"Required"
,
errors
.
New
(
"Required"
)
}
}
ok
,
err
:=
wallet
.
ValidateXXNetworkAddress
(
str
)
ok
,
err
:=
wallet
.
ValidateXXNetworkAddress
(
str
)
if
!
ok
||
err
!=
nil
{
if
!
ok
||
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Invalid wallet address: %s"
,
err
.
Error
())
return
nil
,
"Invalid wallet address"
,
errors
.
Errorf
(
"Invalid wallet address: %s"
,
err
.
Error
())
}
}
return
str
,
nil
return
str
,
""
,
nil
}
}
// ValidateEmail returns an error if the email is invalid. This function adheres
// ValidateEmail returns an error if the email is invalid. This function adheres
// to the ValidateFunc type.
// to the ValidateFunc type.
func
ValidateEmail
(
str
string
)
(
interface
{},
error
)
{
func
ValidateEmail
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
{
return
""
,
nil
return
""
,
""
,
nil
}
}
_
,
err
:=
mail
.
ParseAddress
(
str
)
_
,
err
:=
mail
.
ParseAddress
(
str
)
return
str
,
err
return
str
,
"Invalid email address"
,
err
}
}
// ValidateMultiplier returns an error if the xx network address is
// ValidateMultiplier returns an error if the xx network address is
// invalid.
// invalid.
func
ValidateMultiplier
(
max
uint64
)
ValidateFunc
{
func
ValidateMultiplier
(
max
uint64
)
ValidateFunc
{
return
func
(
str
string
)
(
interface
{},
error
)
{
return
func
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
{
return
nil
,
errors
.
New
(
"Required
.
"
)
return
nil
,
"Required"
,
errors
.
New
(
"Required"
)
}
}
u64
,
err
:=
strconv
.
ParseUint
(
str
,
10
,
64
)
u64
,
err
:=
strconv
.
ParseUint
(
str
,
10
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
"Invalid integer"
,
err
}
}
if
u64
<
0
||
u64
>
max
{
if
u64
<
0
||
u64
>
max
{
return
nil
,
errors
.
Errorf
(
helpText
:=
fmt
.
Sprintf
(
"Must be between %d and %d"
,
0
,
max
)
return
nil
,
helpText
,
errors
.
Errorf
(
"value must be between %d and %d"
,
0
,
max
)
"value must be between %d and %d"
,
0
,
max
)
}
}
return
u64
,
nil
return
u64
,
""
,
nil
}
}
}
}
// ValidateFilePath returns an error if the file path is invalid. This function
// ValidateFilePath returns an error if the file path is invalid. This function
// adheres to the ValidateFunc type.
// adheres to the ValidateFunc type.
func
ValidateFilePath
(
str
string
)
(
interface
{},
error
)
{
func
ValidateFilePath
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
||
str
==
"No file chosen"
{
return
nil
,
errors
.
New
(
"Required
.
"
)
return
nil
,
"Required"
,
errors
.
New
(
"Required"
)
}
}
file
,
err
:=
utils
.
ReadFile
(
str
)
file
,
err
:=
utils
.
ReadFile
(
str
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
"Failed to read file"
,
err
}
}
return
file
,
nil
return
file
,
""
,
nil
}
}
// ValidateIdfPath returns an error if the IDF file path is invalid. This
// ValidateIdfPath returns an error if the IDF file path is invalid. This
// function adheres to the ValidateFunc type.
// function adheres to the ValidateFunc type.
func
ValidateIdfPath
(
str
string
)
(
interface
{},
error
)
{
func
ValidateIdfPath
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
||
str
==
"No file chosen"
{
return
nil
,
errors
.
New
(
"Required
.
"
)
return
nil
,
"Required"
,
errors
.
New
(
"Required"
)
}
}
_
,
nid
,
err
:=
idf
.
UnloadIDF
(
str
)
_
,
nid
,
err
:=
idf
.
UnloadIDF
(
str
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
"Failed to read IDF"
,
err
}
}
return
nid
.
HexEncode
(),
nil
return
nid
.
HexEncode
(),
""
,
nil
}
}
// ValidateCheckbox returns an error if the checkbox is not checked. This
// ValidateCheckbox returns an error if the checkbox is not checked. This
// function adheres to the ValidateFunc type.
// function adheres to the ValidateFunc type.
func
ValidateCheckbox
(
str
string
)
(
interface
{},
error
)
{
func
ValidateCheckbox
(
str
string
)
(
interface
{},
string
,
error
)
{
if
len
(
str
)
==
0
{
if
len
(
str
)
==
0
{
return
nil
,
errors
.
New
(
"Required
.
"
)
return
nil
,
"Required"
,
errors
.
New
(
"Required"
)
}
}
return
true
,
nil
return
true
,
""
,
nil
}
}
This diff is collapsed.
Click to expand it.
main.js
+
13
−
16
View file @
9ffa6498
...
@@ -129,24 +129,21 @@ start_process();
...
@@ -129,24 +129,21 @@ start_process();
function
changeRangeValue
(
val
,
max
)
{
function
changeRangeValue
(
val
,
max
)
{
val
=
val
.
replace
(
/
\D
/g
,
''
);
if
(
val
>
max
)
{
if
(
val
>
max
)
{
console
.
log
(
"
here 1
"
)
val
=
max
;
document
.
getElementById
(
"
number
"
).
value
=
max
;
}
else
if
(
val
<
0
)
{
}
else
if
(
val
<
0
)
{
console
.
log
(
"
here 2
"
)
val
=
0
;
document
.
getElementById
(
"
number
"
).
value
=
0
;
}
else
if
(
val
==
"
-0
"
)
{
}
else
if
(
val
==
"
-0
"
)
{
console
.
log
(
"
here 3
"
)
val
=
0
;
document
.
getElementById
(
"
number
"
).
value
=
0
;
}
else
if
(
val
%
1
!=
0
)
{
}
else
if
(
val
%
1
!=
0
)
{
console
.
log
(
"
here 4
"
)
val
=
Math
.
floor
(
val
);
document
.
getElementById
(
"
number
"
).
value
=
Math
.
floor
(
val
);
}
else
if
(
val
.
length
>
7
)
{
}
else
if
(
val
.
length
>
7
)
{
console
.
log
(
"
here 6
"
)
val
=
val
.
slice
(
0
,
7
);
val
=
val
.
slice
(
0
,
7
);
}
if
(
val
.
length
>
0
)
{
document
.
getElementById
(
"
number
"
).
value
=
val
;
document
.
getElementById
(
"
number
"
).
value
=
val
;
}
}
console
.
log
(
"
here 7
"
+
val
)
document
.
getElementById
(
"
range
"
).
value
=
isNaN
(
parseInt
(
val
,
10
))
?
0
:
parseInt
(
val
,
10
);
document
.
getElementById
(
"
range
"
).
value
=
isNaN
(
parseInt
(
val
,
10
))
?
0
:
parseInt
(
val
,
10
);
}
}
...
...
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