Skip to content

Commit

Permalink
Updated documentation, changed the parameter list and handling in the…
Browse files Browse the repository at this point in the history
… autonumeric function, simplified the binding so there is only one.
  • Loading branch information
srmatth committed Aug 11, 2020
1 parent 4d2354a commit e586375
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 712 deletions.
553 changes: 263 additions & 290 deletions R/input-autonumeric.R

Large diffs are not rendered by default.

149 changes: 11 additions & 138 deletions inst/assets/autonumeric/autonumeric-bindings.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,4 @@
// Currency Input Binding
var currencyInputBinding = new Shiny.InputBinding();
$.extend(currencyInputBinding, {

find: function(scope) {
return $(scope).find(".currency-input");
},

initialize: function(el) {
var config = $(el)
.parent()
.find('script[data-for="' + el.id + '"]');
config = JSON.parse(config.html());
this[el.id] = new AutoNumeric(el, config.format);
},

getValue: function(el) {
return this[el.id].getNumber();
},

subscribe: function(el, callback) {
$(el).on("change keyup input", function(event) {
callback();
});
},

unsubscribe: function(el) {
$(el).off(".currencyInputBinding");
},

receiveMessage: function(el, data) {
if (data.hasOwnProperty("value")) {
this[el.id].set(data.value);
}

if (data.hasOwnProperty("format")) {
this[el.id].update(data.format);
}

if (data.hasOwnProperty("label"))
$(el)
.parent()
.parent()
.find('label[for="' + Shiny.$escape(el.id) + '"]')
.text(data.label);

$(el).trigger("change");
},

getState: function(el) {
return{
label: $(el)
.parent()
.parent()
.find('label[for="' + Shiny.$escape(el.id) + '"]')
.text(),
value: this[el.id].getNumber(),
options: this[el.id].getSettings()
};
},

getRatePolicy: function() {
return {
policy: "debounce",
delay: 500
};
}
});

Shiny.inputBindings.register(currencyInputBinding, "shinyWidgets.currencyInput");

// Autonumeric input binding

// Autonumeric Input Binding
var autonumericInputBinding = new Shiny.InputBinding();
$.extend(autonumericInputBinding, {

Expand All @@ -83,79 +11,21 @@ $.extend(autonumericInputBinding, {
.parent()
.find('script[data-for="' + el.id + '"]');
config = JSON.parse(config.html());

console.log(config);
this[el.id] = new AutoNumeric(el, {
currencySymbol : config.currencySymbol,
currencySymbolPlacement : config.currencySymbolPlacement,
decimalCharacter : config.decimalCharacter,
digitGroupSeparator : config.digitGroupSeparator,
allowDecimalPadding : config.allowDecimalPadding,
decimalPlaces : config.decimalPlaces,
decimalPlacesRawValue : config.decimalPlacesRawValue,
decimalPlacesShownOnBlur : config.decimalPlacesShownOnBlur,
decimalPlacesShownOnFocus : config.decimalPlacesShownOnFocus,
digitalGroupSpacing : config.digitalGroupSpacing,
alwaysAllowDecimalCharacter : config.alwaysAllowDecimalCharacter,
createLocalList : config.createLocalList,
decimalCharacterAlternative : config.decimalCharacterAlternative,
divisorWhenUnfocused : config.divisorWhenUnfocused,
rawValueDivisor : config.rawValueDivisor,
emptyInputBehavior : config.emptyInputBehavior,
selectNumberOnly : config.selectNumberOnly,
selectOnFocus : config.selectOnFocus,
eventBubbles : config.eventBubbles,
eventIsCancelable : config.eventIsCancelable,
formatOnPageLoad : config.formatOnPageLoad,
formulaMode : config.formulaMode,
historySize : config.historySize,
isCancellable : config.isCancellable,
leadingZero : config.leadingZero,
maximumValue : config.maximumValue,
minimumValue : config.minimumValue,
modifyValueOnWheel : config.modifyValueOnWheel,
wheelOn : config.wheelOn,
wheelStep : config.wheelStep,
negativeBracketsTypeOnBlur : config.negativeBracketsTypeOnBlur,
negativePositiveSignPlacement : config.negativePositiveSignPlacement,
negativeSignCharacter : config.negativeSignCharacter,
positiveSignCharacter : config.positiveSignCharacter,
showPositiveSign : config.showPositiveSign,
onInvalidPaste : config.onInvalidPaste,
overrideMinMaxLimits : config.overrideMinMaxLimits,
readOnly : config.readOnly,
roundingMethod : config.roundingMethod,
saveValueToSessionStorage : config.saveValueToSessionStorage,
serializeSpaces : config.serializeSpaces,
showOnlyNumbersOnFocus : config.showOnlyNumbersOnFocus,
showWarnings : config.showWarnings,
styleRules : config.styleRules,
//suffixText : config.suffixText,
symbolWhenUnfocused : config.symbolWhenUnfocused,
unformatOnHover : config.unformatOnHover,
valuesToStrings : config.valuesToStrings,
watchExternalChanges : config.watchExternalChanges
});
if (config.hasOwnProperty("format")) {
this[el.id] = new AutoNumeric(el, config.format);
} else {
this[el.id] = new AutoNumeric(el, config.options);
}
},

getValue: function(el) {
return this[el.id].getNumber();
},

subscribe: function(el, callback) {
var config = $(el)
.parent()
.find('script[data-for="' + el.id + '"]');
config = JSON.parse(config.html());
if (config.immediate) {
$(el).on("keyup.autonumericInputBinding change.autonumericInputBinding", function(event) {
$(el).on("change.autonumericInputBinding keyup.autonumericInputBinding input.autonumericInputBinding", function(event) {
callback();
});
} else {
$(el).on("input.autonumericInputBinding", function(event) {
callback();
});
}
},

unsubscribe: function(el) {
Expand All @@ -167,6 +37,10 @@ $.extend(autonumericInputBinding, {
this[el.id].set(data.value);
}

if (data.hasOwnProperty("format")) {
this[el.id].update(data.format);
}

if (data.hasOwnProperty("options")) {
this[el.id].update(data.options);
}
Expand Down Expand Up @@ -203,4 +77,3 @@ $.extend(autonumericInputBinding, {

Shiny.inputBindings.register(autonumericInputBinding, "shinyWidgets.autonumericInput");


Loading

0 comments on commit e586375

Please sign in to comment.