diff --git a/app/javascript/controllers/enter_controller.js b/app/javascript/controllers/enter_controller.js new file mode 100644 index 00000000..763dd08c --- /dev/null +++ b/app/javascript/controllers/enter_controller.js @@ -0,0 +1,10 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + /* + * Previene el envĂ­o de un formulario al presionar enter + */ + prevent(event) { + if (event.key == "Enter") event.preventDefault(); + } +} diff --git a/app/views/posts/attributes/_new_array.haml b/app/views/posts/attributes/_new_array.haml index 763da9f8..08fc6dee 100644 --- a/app/views/posts/attributes/_new_array.haml +++ b/app/views/posts/attributes/_new_array.haml @@ -5,7 +5,7 @@ name = "#{base}[#{attribute}][]" form_id = "form-#{Nanoid.generate}" -%div{ data: { controller: 'modal array', 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_array_value_path(site) } } +%div{ data: { controller: 'modal array enter', 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_array_value_path(site) } } .form-group = hidden_field_tag name, '' = label_tag id, post_label_t(attribute, post: post) @@ -30,7 +30,7 @@ - content_for :"#{id}_header" do .form-group.flex-grow-1.mb-0 = label_tag id, post_label_t(attribute, post: post) - %input.form-control{ data: { target: 'array.search', action: 'input->array#search' }, type: 'search', placeholder: t('.filter') } + %input.form-control{ data: { target: 'array.search', action: 'input->array#search keydown->enter#prevent' }, type: 'search', placeholder: t('.filter') } - content_for :"#{id}_body" do .form-group.mb-0{ id: "#{id}_body" }