Skip to content

Commit

Permalink
fix: JS errors related to stepper + Undefined vals when updating virt…
Browse files Browse the repository at this point in the history
…ualList
  • Loading branch information
hypebright committed Mar 13, 2024
1 parent 0d131a2 commit 11cbb35
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion inst/shinyMobile-1.0.1/dist/shinyMobile.min.css.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js.map

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions srcjs/bindings/stepperInputBinding.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { getAppInstance } from "../init.js";

// Input binding
var f7StepperBinding = new Shiny.InputBinding();

$.extend(f7StepperBinding, {
app: null,

initialize: function(el) {

this.app = getAppInstance();

// recover the inputId passed in the R function
var id = $(el).attr("id");

Expand All @@ -30,7 +35,7 @@ $.extend(f7StepperBinding, {
data.el = '#' + id;

// feed the create method
var s = app.stepper.create(data);
var s = this.app.stepper.create(data);

// add readonly attr if the stepper is initially
// not in manual mode
Expand All @@ -46,28 +51,33 @@ $.extend(f7StepperBinding, {

// Given the DOM element for the input, return the value
getValue: function(el) {
return app.stepper.get($(el)).value;
this.app = getAppInstance();
return this.app.stepper.get($(el)[0]).value;
},

// see updateF7Stepper
setValue: function(el, value) {
app.stepper.setValue(el, value);
this.app = getAppInstance();
this.app.stepper.setValue(el, value);
},

// the 2 methods below are needed by incrementF7Stepper
// and decrementF7Stepper
increment: function() {
app.stepper.increment();
this.app = getAppInstance();
this.app.stepper.increment();
},

decrement: function() {
app.stepper.decrement();
this.app = getAppInstance();
this.app.stepper.decrement();
},

// see updateF7Stepper
receiveMessage: function(el, data) {
this.app = getAppInstance();
// create a variable to update the stepper
var s = app.stepper.get($(el));
var s = this.app.stepper.get($(el));

// for some reason, we need to update both
// min and params.min fields
Expand Down Expand Up @@ -163,12 +173,13 @@ $.extend(f7StepperBinding, {
},

subscribe: function(el, callback) {
this.app = getAppInstance();
$(el).on('stepper:change.f7StepperBinding', function(e) {
// no need to debounce here
// except if autorepeat is set
// then we send the value once
// the + or - buttons is released
var s = app.stepper.get($(el));
var s = this.app.stepper.get($(el));
if (s.params.autorepeat) {
callback(true);
} else {
Expand Down
10 changes: 5 additions & 5 deletions srcjs/bindings/virtualListBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ $.extend(f7VirtualListBinding, {
'<div class="item-title-row">' +
'<div class="item-title">' +
'<div class="item-header">' +
item.header +
(item.header === undefined ? "" : item.header) +
"</div>" +
item.title +
(item.title === undefined ? "" : item.title) +
'<div class="item-footer">' +
item.footer +
(item.footer === undefined ? "" : item.footer) +
"</div>" +
"</div>" +
'<div class="item-after">' +
item.right +
(item.right === undefined ? "" : item.right) +
"</div>" +
"</div>" +
'<div class="item-subtitle">' +
item.subtitle +
(item.subtitle === undefined ? "" : item.subtitle) +
"</div>" +
'<div class="item-text">' +
item.content +
Expand Down

0 comments on commit 11cbb35

Please sign in to comment.