Skip to content

Commit c1e1dbd

Browse files
committed
reactShinyInput: introduce options.type to support shiny::registerInputHandler()
1 parent 6ace2ed commit c1e1dbd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

srcjs/input.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function defaultReceiveMessage(el, { configuration, value }) {
2828
}
2929

3030
const defaultOptions = {
31-
receiveMessage: defaultReceiveMessage
31+
receiveMessage: defaultReceiveMessage,
32+
type: false
3233
};
3334

3435
/**
@@ -44,6 +45,16 @@ const defaultOptions = {
4445
* - receiveMessage: Implementation of Shiny.InputBinding to use in place of
4546
* the default. Typically overridden as an optimization to perform
4647
* incremental value updates.
48+
* - type: `false`, a string, or a function.
49+
* - `false` (the default): denotes that the value produced by this input
50+
* should not be intercepted by any handlers registered in R on the
51+
* server using shiny::registerInputHandler().
52+
* - string: denotes the input's *type* and should correspond to the
53+
* type parameter of shiny::registerInputHandler().
54+
* - function: A function called with `this` bound to the InputBinding
55+
* instance and passed a single argument, the input's containing DOM
56+
* element. The function should return either `false` or a string
57+
* corresponding to the type parameter of shiny::registerInputHandler().
4758
*/
4859
export function reactShinyInput(selector,
4960
name,
@@ -82,11 +93,20 @@ export function reactShinyInput(selector,
8293
receiveMessage(el, data) {
8394
options.receiveMessage.call(this, el, data);
8495
}
96+
getType(el) {
97+
if (typeof options.type === 'function') {
98+
return options.type.call(this, el);
99+
} else if (options.type === false || typeof options.type === 'string') {
100+
return options.type;
101+
} else {
102+
throw new Error('options.type must be false, a string, or a function');
103+
}
104+
}
85105

86106
/*
87107
* Methods not present in Shiny.InputBinding but accessible to users
88108
* through `this` in receiveMessage
89-
* */
109+
*/
90110

91111
getInputValue(el) {
92112
return $(el).data('value');

0 commit comments

Comments
 (0)