From 9bbc7abfd9637c270ea15ff284aee4f5afbb7fd2 Mon Sep 17 00:00:00 2001 From: Joseph Solomon Date: Thu, 16 Mar 2017 11:12:16 -0400 Subject: [PATCH 1/2] allow the input element name to be updated Useful when using formset's in Django. Will attempt to find the element set by the name but if it does not exist, set's the element id to the default Django id format. --- src/trix/elements/trix_editor_element.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/trix/elements/trix_editor_element.coffee b/src/trix/elements/trix_editor_element.coffee index 640659997..ce485834e 100644 --- a/src/trix/elements/trix_editor_element.coffee +++ b/src/trix/elements/trix_editor_element.coffee @@ -109,6 +109,12 @@ Trix.registerElement "trix-editor", do -> name: get: -> @inputElement?.name + set: (inputElementName) -> + newInputElement = document.getElementsByName(inputElementName)[0] + if newInputElement + @setAttribute("input", newInputElement.id) + else + @setAttribute("input", "id_" + inputElementName)} value: get: -> From c6ebc7fdea13989f5adeb7e48867e4a09d365a2c Mon Sep 17 00:00:00 2001 From: Joseph Solomon Date: Thu, 16 Mar 2017 11:31:11 -0400 Subject: [PATCH 2/2] Update trix_editor_element.coffee --- src/trix/elements/trix_editor_element.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trix/elements/trix_editor_element.coffee b/src/trix/elements/trix_editor_element.coffee index ce485834e..f6340fdf9 100644 --- a/src/trix/elements/trix_editor_element.coffee +++ b/src/trix/elements/trix_editor_element.coffee @@ -114,7 +114,7 @@ Trix.registerElement "trix-editor", do -> if newInputElement @setAttribute("input", newInputElement.id) else - @setAttribute("input", "id_" + inputElementName)} + @setAttribute("input", "id_" + inputElementName) value: get: ->