Skip to content

Commit

Permalink
Bound check sliders in web UI (PhotonVision#1134)
Browse files Browse the repository at this point in the history
* Bound check sliders

* Update pv-range-slider.vue

---------

Co-authored-by: Sriman Achanta <[email protected]>
  • Loading branch information
mcm001 and srimanachanta authored Jan 8, 2024
1 parent 4d45819 commit 02df8aa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions photon-client/src/components/common/pv-range-slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ const localValue = computed<[number, number]>({
}
});
const changeFromSlot = (v: number, i: number) => {
const changeFromSlot = (v: string, i: number) => {
// v comes in as a string, not a number, for some reason
// if v is undefined, take a guess and set it to 0
const val = Math.max(props.min, Math.min(parseFloat(v) || 0, props.max));
// localValue.value must be replaced for a reactive change to take place
const temp = localValue.value;
temp[i] = v;
temp[i] = val;
localValue.value = temp;
};
const checkNumberRange = (v: string): boolean => {
const val: number = parseFloat(v);
return isFinite(val) && val >= props.min && val <= props.max;
};
</script>

<template>
Expand Down Expand Up @@ -79,6 +88,7 @@ const changeFromSlot = (v: number, i: number) => {
:max="max"
:min="min"
:step="step"
:rules="[checkNumberRange]"
type="number"
style="width: 60px"
@input="(v) => changeFromSlot(v, 0)"
Expand All @@ -95,6 +105,7 @@ const changeFromSlot = (v: number, i: number) => {
:max="max"
:min="min"
:step="step"
:rules="[checkNumberRange]"
type="number"
style="width: 60px"
@input="(v) => changeFromSlot(v, 1)"
Expand Down

0 comments on commit 02df8aa

Please sign in to comment.