forked from MapComplete/MapComplete
Move Orientation into sensors directory, attempt to fix 'NaN' in slope input
This commit is contained in:
parent
82409984dc
commit
e9268bfc49
6 changed files with 30 additions and 6 deletions
|
@ -1,4 +1,3 @@
|
|||
import NatValidator from "./NatValidator"
|
||||
import FloatValidator from "./FloatValidator"
|
||||
|
||||
export default class SlopeValidator extends FloatValidator {
|
||||
|
@ -9,10 +8,36 @@ export default class SlopeValidator extends FloatValidator {
|
|||
"The accompanying input element uses the gyroscope and the compass to determine the correct incline. The sign of the incline will be set automatically. The bearing of the way is compared to the bearing of the compass, as such, the device knows if it is measuring in the forward or backward direction."
|
||||
)
|
||||
}
|
||||
|
||||
isValid(str: string): boolean {
|
||||
if (str.endsWith("%") || str.endsWith("°")) {
|
||||
str = str.substring(0, str.length - 1)
|
||||
}
|
||||
return super.isValid(str)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* const v = new SlopeValidator()
|
||||
* v.reformat("5%") // => "5%"
|
||||
* v.reformat("5 %") // => "5%"
|
||||
* v.reformat(" 5 %") // => "5%"
|
||||
* v.reformat(" 5.0 %") // => "5%"
|
||||
* v.reformat(" 5.0 % ") // => "5%"
|
||||
* v.reformat(" -5.0 % ") // => "-5%"
|
||||
* v.reformat("5") // => "5"
|
||||
* v.reformat("5°") // => "5°"
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
reformat(str: string): string {
|
||||
str = str.trim()
|
||||
let lastChar = ""
|
||||
if (str.endsWith("%") || str.endsWith("°")) {
|
||||
lastChar = str.substring(str.length - 1)
|
||||
str = str.substring(0, str.length - 1)
|
||||
}
|
||||
return super.reformat(str) + lastChar
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue