Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: missing attribute values causing runtime error #205

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ guide the learner’s interaction with the component.

**labelEnd** (string): Text/characters that appear at the end of the slider scale.

**\_scaleStart** (number): This value is the numeric start of the scale. It is used to calculate the slider's position on the scale.
**\_scaleStart** (number): This value is the numeric start of the scale. It is used to calculate the slider's position on the scale. The default is `1`.

**\_scaleEnd** (number): This value is the numeric end of the scale. It is used to calculate the slider's position on the scale.
**\_scaleEnd** (number): This value is the numeric end of the scale. It is used to calculate the slider's position on the scale. The default is `10`.

**\_scaleStep** (number): Defines the amount the scale should be incremented by.
**\_scaleStep** (number): Defines the amount the scale should be incremented by. The default is `1`.

**scaleStepPrefix** (string): Prefix to add to each slider step. For example, a "$" can be used as a prefix to indicate currency in dollars (ex. $100).

Expand Down
7 changes: 5 additions & 2 deletions js/SliderModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default class SliderModel extends QuestionModel {

defaults() {
return QuestionModel.resultExtend('defaults', {
_scaleStart: 1,
_scaleEnd: 10,
_scaleStep: 1,
_showScale: true,
_showScaleNumbers: true,
_showScaleIndicator: true,
Expand Down Expand Up @@ -49,7 +52,7 @@ export default class SliderModel extends QuestionModel {
const range = this.get('_correctRange');
const start = this.get('_scaleStart');
const end = this.get('_scaleEnd');
const step = this.get('_scaleStep') || 1;
const step = this.get('_scaleStep');

const dp = this.getDecimalPlaces(step);

Expand Down Expand Up @@ -177,7 +180,7 @@ export default class SliderModel extends QuestionModel {
return answers;
}
let answer = bottom;
const step = this.get('_scaleStep') || 1;
const step = this.get('_scaleStep');
while (answer <= top) {
answers.push(answer);
answer += step;
Expand Down
2 changes: 1 addition & 1 deletion js/SliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SliderView extends QuestionView {
// this shoud give the index of item using given slider value
getIndexFromValue(value) {
value = parseFloat(value);
const step = this.model.get('_scaleStep') ?? 1;
const step = this.model.get('_scaleStep');
return this.model.get('_items').reduce((found, item) => {
if (found) return found;
if (item.value === value) return item;
Expand Down
2 changes: 1 addition & 1 deletion properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"_scaleEnd": {
"type": "number",
"required": true,
"default": 1,
"default": 10,
"title": "Scale End",
"inputType": "Number",
"validators": ["required", "number"],
Expand Down
2 changes: 1 addition & 1 deletion schema/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"_scaleEnd": {
"type": "number",
"title": "Scale end number",
"default": 1
"default": 10
},
"_scaleStep": {
"type": "number",
Expand Down