-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#' The \strong{input} editor allows entering of a single line of plain text | ||
#' | ||
#' @param widget A [tabulator()] HTML widget. | ||
#' @param column The name of the column the formatter is applied to. | ||
#' @param search Use search type input element with clear button | ||
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order | ||
#' @param select_contents When the editor is loaded select its text content | ||
#' @param elementAttributes Set attributes directly on the input element | ||
#' | ||
#' @return The updated [tabulator()] HTML widget | ||
#' @export | ||
#' | ||
#' @examples examples/editors/editor_input | ||
set_column_editor_input <- function(widget, | ||
columns, | ||
search = TRUE, | ||
mask = "", | ||
select_contents = TRUE, | ||
elementAttributes = list( | ||
maxlength = 10 | ||
)){ | ||
editor = "input" | ||
editorParams = list( | ||
search = search, | ||
mask = mask, | ||
selectContents = select_contents, | ||
elementAttributes = elementAttributes | ||
) | ||
|
||
set_column_editor(widget, columns, editor, editorParams) | ||
} | ||
|
||
#' The \strong{textarea} editor allows entering of multiple lines of plain text | ||
#' @inherit set_column_editor_input params return | ||
#' @param elementAttributes Set attributes directly on the textarea element | ||
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order | ||
#' @param select_contents When the editor is loaded select its text content | ||
#' @param vertical_navigation Determine how use of the up/down arrow keys will affect the editor, | ||
#' this can take three different types of value: *hybrid*, *editor* and *table* | ||
#' @param shift_enter_submit Submit the cell value when the shift and enter keys are pressed | ||
#' | ||
#' @export | ||
#' | ||
set_column_editor_text_area <- function(widget, | ||
columns, | ||
elementAttributes = list( | ||
maxlength = 10 | ||
), | ||
mask = "", | ||
select_contents = TRUE, | ||
vertical_navigation = "editor", | ||
shift_enter_submit = TRUE | ||
){ | ||
editor = "textarea" | ||
editorParams = list( | ||
elementAttributes = elementAttributes, | ||
mask = mask, | ||
selectContents = select_contents, | ||
verticalNavigation = vertical_navigation, | ||
shiftEnterSubmit = shift_enter_submit | ||
) | ||
|
||
set_column_editor(widget, columns, editor, editorParams) | ||
} | ||
|
||
#' The \strong{numeric} editor allows for numeric entry with a number type input element with increment and decrement buttons. | ||
#' @inherit set_column_editor_input params return | ||
#' @param min the maximum allowed value | ||
#' @param max the minimum allowed value | ||
#' @param step the step size when incrementing/decrementing the value (default 1) | ||
#' @param elementAttributes Set attributes directly on the element | ||
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order | ||
#' @param select_contents When the editor is loaded select its text content | ||
#' @param vertical_navigation determine how use of the up/down arrow keys will affect the editor, | ||
#' this can take two different types of value: : *editor* and *table* | ||
#' @export | ||
#' | ||
set_column_editor_numeric <- function(widget, | ||
columns, | ||
min = 0, | ||
max = 100, | ||
step = 1, | ||
elementAttributes = list( | ||
maxlength = 10 | ||
), | ||
mask = "", | ||
select_contents = TRUE, | ||
vertical_navigation = "table" | ||
){ | ||
editor = "number" | ||
editorParams = list( | ||
min = min, | ||
max = max, | ||
elementAttributes = elementAttributes, | ||
mask = mask, | ||
selectContents = select_contents, | ||
verticalNavigation = vertical_navigation | ||
) | ||
|
||
set_column_editor(widget, columns, editor, editorParams) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
test_that("set editor input", { | ||
# Prepare | ||
col = "input_var" | ||
df <- data.frame(input_var = c("a","b","c")) | ||
|
||
|
||
# Act | ||
t <- tabulator(df) |> | ||
set_column_editor_input(col) | ||
|
||
# Assert | ||
expected_column_def <- list( | ||
title = "input_var", | ||
field = "input_var", | ||
hozAlign = "left", | ||
editor = "input", | ||
editorParams = list( | ||
search = TRUE, | ||
mask = "", | ||
selectContents = TRUE, | ||
elementAttributes = list( | ||
maxlength = 10 | ||
) | ||
) | ||
) | ||
expect_mapequal(t$x$options$columns[[1]], expected_column_def) | ||
expect_s3_class(t, "rtabulator") | ||
expect_s3_class(t, "htmlwidget") | ||
}) | ||
|
||
test_that("set editor area input", { | ||
# Prepare | ||
col = "input_var" | ||
df <- data.frame(input_var = c("a","b","c")) | ||
|
||
|
||
# Act | ||
t <- tabulator(df) |> | ||
set_column_editor_text_area(col) | ||
|
||
# Assert | ||
expected_column_def <- list( | ||
title = "input_var", | ||
field = "input_var", | ||
hozAlign = "left", | ||
editor = "textarea", | ||
editorParams = list( | ||
elementAttributes = list( | ||
maxlength = 10 | ||
), | ||
mask = "", | ||
selectContents = TRUE, | ||
verticalNavigation = "editor", | ||
shiftEnterSubmit = TRUE | ||
) | ||
) | ||
expect_mapequal(t$x$options$columns[[1]], expected_column_def) | ||
expect_s3_class(t, "rtabulator") | ||
expect_s3_class(t, "htmlwidget") | ||
}) | ||
|
||
|
File renamed without changes.