diff --git a/assets/js/app.js b/assets/js/app.js index 074f355..51a0d20 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -30,6 +30,7 @@ import topbar from 'topbar' import CtrlEnter from './ctrlenter' import Date from './date' import DateTime from './datetime' +import SanitizeTags from './sanitizetags' import SanitizeTitles from './sanitizetitles' const csrfTokenElement = document.querySelector("meta[name='csrf-token']") @@ -37,7 +38,7 @@ let csrfToken if (csrfTokenElement) { csrfToken = csrfTokenElement.getAttribute('content') } const liveSocket = new LiveSocket('/live', Socket, { params: { _csrf_token: csrfToken }, - hooks: { CtrlEnter, Date, DateTime, SanitizeTitles } + hooks: { CtrlEnter, Date, DateTime, SanitizeTags, SanitizeTitles } }) // Show progress bar on live navigation and form submits diff --git a/assets/js/sanitizetags.js b/assets/js/sanitizetags.js new file mode 100644 index 0000000..f0e3bca --- /dev/null +++ b/assets/js/sanitizetags.js @@ -0,0 +1,11 @@ +export default { + SanitizeTags (context) { + context.el.addEventListener('keyup', (e) => { + e.target.value = e.target.value + .replace(' ', ',') + .replace(',,', ',') + .replace(/[^a-zA-Z0-9,]/, '') + }) + }, + mounted () { this.SanitizeTags(this) } +} diff --git a/changelog.md b/changelog.md index 863291e..861047f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # v0.1.15 - Sanitize titles while they are being typed +- Sanitize tags while they are being typed - Remove requirement for note and content to have content - Prevent possible additional submissions - Fix content being displayed when blank diff --git a/lib/memex_web/live/context_live/form_component.html.heex b/lib/memex_web/live/context_live/form_component.html.heex index d0a55de..67bbc9b 100644 --- a/lib/memex_web/live/context_live/form_component.html.heex +++ b/lib/memex_web/live/context_live/form_component.html.heex @@ -31,11 +31,12 @@ <%= error_tag(f, :content) %> <%= text_input(f, :tags_string, - id: "tags-input", - class: "input input-primary", - placeholder: gettext("tag1,tag2"), aria_label: gettext("tag1,tag2"), - phx_debounce: 300 + class: "input input-primary", + id: "tags-input", + phx_debounce: 300, + phx_hook: "SanitizeTags", + placeholder: gettext("tag1,tag2") ) %> <%= error_tag(f, :tags_string) %> diff --git a/lib/memex_web/live/note_live/form_component.html.heex b/lib/memex_web/live/note_live/form_component.html.heex index 4130baa..3eb2400 100644 --- a/lib/memex_web/live/note_live/form_component.html.heex +++ b/lib/memex_web/live/note_live/form_component.html.heex @@ -29,11 +29,12 @@ <%= error_tag(f, :content) %> <%= text_input(f, :tags_string, - id: "tags-input", - class: "input input-primary", - placeholder: gettext("tag1,tag2"), aria_label: gettext("tag1,tag2"), - phx_debounce: 300 + class: "input input-primary", + id: "tags-input", + phx_debounce: 300, + phx_hook: "SanitizeTags", + placeholder: gettext("tag1,tag2") ) %> <%= error_tag(f, :tags_string) %> diff --git a/lib/memex_web/live/pipeline_live/form_component.html.heex b/lib/memex_web/live/pipeline_live/form_component.html.heex index 37477ef..0fe012c 100644 --- a/lib/memex_web/live/pipeline_live/form_component.html.heex +++ b/lib/memex_web/live/pipeline_live/form_component.html.heex @@ -35,11 +35,12 @@ <%= error_tag(f, :description) %> <%= text_input(f, :tags_string, - id: "tags-input", - class: "input input-primary", - placeholder: gettext("tag1,tag2"), aria_label: gettext("tag1,tag2"), - phx_debounce: 300 + class: "input input-primary", + id: "tags-input", + phx_debounce: 300, + phx_hook: "SanitizeTags", + placeholder: gettext("tag1,tag2") ) %> <%= error_tag(f, :tags_string) %> diff --git a/priv/gettext/actions.pot b/priv/gettext/actions.pot index dcb6b70..e88778d 100644 --- a/priv/gettext/actions.pot +++ b/priv/gettext/actions.pot @@ -108,10 +108,10 @@ msgstr "" msgid "register" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:50 +#: lib/memex_web/live/context_live/form_component.html.heex:51 #: lib/memex_web/live/invite_live/form_component.html.heex:47 -#: lib/memex_web/live/note_live/form_component.html.heex:48 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:54 +#: lib/memex_web/live/note_live/form_component.html.heex:49 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 #: lib/memex_web/live/step_live/form_component.html.heex:38 #, elixir-autogen, elixir-format msgid "save" diff --git a/priv/gettext/de/LC_MESSAGES/actions.po b/priv/gettext/de/LC_MESSAGES/actions.po index 9eb5416..6355126 100644 --- a/priv/gettext/de/LC_MESSAGES/actions.po +++ b/priv/gettext/de/LC_MESSAGES/actions.po @@ -108,10 +108,10 @@ msgstr "" msgid "register" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:50 +#: lib/memex_web/live/context_live/form_component.html.heex:51 #: lib/memex_web/live/invite_live/form_component.html.heex:47 -#: lib/memex_web/live/note_live/form_component.html.heex:48 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:54 +#: lib/memex_web/live/note_live/form_component.html.heex:49 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 #: lib/memex_web/live/step_live/form_component.html.heex:38 #, elixir-autogen, elixir-format msgid "save" diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index cd02939..d96a09f 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -237,20 +237,20 @@ msgstr "" msgid "report bugs or request features" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:51 -#: lib/memex_web/live/note_live/form_component.html.heex:49 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 +#: lib/memex_web/live/context_live/form_component.html.heex:52 +#: lib/memex_web/live/note_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:56 #: lib/memex_web/live/step_live/form_component.html.heex:39 #, elixir-autogen, elixir-format msgid "saving..." msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:45 #: lib/memex_web/live/context_live/form_component.html.heex:46 -#: lib/memex_web/live/note_live/form_component.html.heex:43 +#: lib/memex_web/live/context_live/form_component.html.heex:47 #: lib/memex_web/live/note_live/form_component.html.heex:44 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:49 +#: lib/memex_web/live/note_live/form_component.html.heex:45 #: lib/memex_web/live/pipeline_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:51 #, elixir-autogen, elixir-format msgid "select privacy" msgstr "" @@ -266,12 +266,12 @@ msgstr "" msgid "settings" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:36 -#: lib/memex_web/live/context_live/form_component.html.heex:37 -#: lib/memex_web/live/note_live/form_component.html.heex:34 -#: lib/memex_web/live/note_live/form_component.html.heex:35 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:40 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:41 +#: lib/memex_web/live/context_live/form_component.html.heex:34 +#: lib/memex_web/live/context_live/form_component.html.heex:39 +#: lib/memex_web/live/note_live/form_component.html.heex:32 +#: lib/memex_web/live/note_live/form_component.html.heex:37 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:38 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:43 #, elixir-autogen, elixir-format msgid "tag1,tag2" msgstr "" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index df5cefd..db4ba08 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -235,20 +235,20 @@ msgstr "" msgid "report bugs or request features" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:51 -#: lib/memex_web/live/note_live/form_component.html.heex:49 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 +#: lib/memex_web/live/context_live/form_component.html.heex:52 +#: lib/memex_web/live/note_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:56 #: lib/memex_web/live/step_live/form_component.html.heex:39 #, elixir-autogen, elixir-format msgid "saving..." msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:45 #: lib/memex_web/live/context_live/form_component.html.heex:46 -#: lib/memex_web/live/note_live/form_component.html.heex:43 +#: lib/memex_web/live/context_live/form_component.html.heex:47 #: lib/memex_web/live/note_live/form_component.html.heex:44 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:49 +#: lib/memex_web/live/note_live/form_component.html.heex:45 #: lib/memex_web/live/pipeline_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:51 #, elixir-autogen, elixir-format msgid "select privacy" msgstr "" @@ -264,12 +264,12 @@ msgstr "" msgid "settings" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:36 -#: lib/memex_web/live/context_live/form_component.html.heex:37 -#: lib/memex_web/live/note_live/form_component.html.heex:34 -#: lib/memex_web/live/note_live/form_component.html.heex:35 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:40 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:41 +#: lib/memex_web/live/context_live/form_component.html.heex:34 +#: lib/memex_web/live/context_live/form_component.html.heex:39 +#: lib/memex_web/live/note_live/form_component.html.heex:32 +#: lib/memex_web/live/note_live/form_component.html.heex:37 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:38 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:43 #, elixir-autogen, elixir-format msgid "tag1,tag2" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/actions.po b/priv/gettext/en/LC_MESSAGES/actions.po index 36b49a7..852740f 100644 --- a/priv/gettext/en/LC_MESSAGES/actions.po +++ b/priv/gettext/en/LC_MESSAGES/actions.po @@ -109,10 +109,10 @@ msgstr "" msgid "register" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:50 +#: lib/memex_web/live/context_live/form_component.html.heex:51 #: lib/memex_web/live/invite_live/form_component.html.heex:47 -#: lib/memex_web/live/note_live/form_component.html.heex:48 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:54 +#: lib/memex_web/live/note_live/form_component.html.heex:49 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 #: lib/memex_web/live/step_live/form_component.html.heex:38 #, elixir-autogen, elixir-format msgid "save" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index f489938..29b8273 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -236,20 +236,20 @@ msgstr "" msgid "report bugs or request features" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:51 -#: lib/memex_web/live/note_live/form_component.html.heex:49 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:55 +#: lib/memex_web/live/context_live/form_component.html.heex:52 +#: lib/memex_web/live/note_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:56 #: lib/memex_web/live/step_live/form_component.html.heex:39 #, elixir-autogen, elixir-format msgid "saving..." msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:45 #: lib/memex_web/live/context_live/form_component.html.heex:46 -#: lib/memex_web/live/note_live/form_component.html.heex:43 +#: lib/memex_web/live/context_live/form_component.html.heex:47 #: lib/memex_web/live/note_live/form_component.html.heex:44 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:49 +#: lib/memex_web/live/note_live/form_component.html.heex:45 #: lib/memex_web/live/pipeline_live/form_component.html.heex:50 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:51 #, elixir-autogen, elixir-format msgid "select privacy" msgstr "" @@ -265,12 +265,12 @@ msgstr "" msgid "settings" msgstr "" -#: lib/memex_web/live/context_live/form_component.html.heex:36 -#: lib/memex_web/live/context_live/form_component.html.heex:37 -#: lib/memex_web/live/note_live/form_component.html.heex:34 -#: lib/memex_web/live/note_live/form_component.html.heex:35 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:40 -#: lib/memex_web/live/pipeline_live/form_component.html.heex:41 +#: lib/memex_web/live/context_live/form_component.html.heex:34 +#: lib/memex_web/live/context_live/form_component.html.heex:39 +#: lib/memex_web/live/note_live/form_component.html.heex:32 +#: lib/memex_web/live/note_live/form_component.html.heex:37 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:38 +#: lib/memex_web/live/pipeline_live/form_component.html.heex:43 #, elixir-autogen, elixir-format msgid "tag1,tag2" msgstr ""