Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: cmd+return to submit form #3532

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/components/avo/views/resource_edit_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
method: form_method,
local: true,
html: {
novalidate: true
novalidate: true,
data: {
controller: "form",
action: "keydown.ctrl+enter->form#submit keydown.meta+enter->form#submit"
}
},
multipart: true do |form| %>
<%= render Avo::ReferrerParamsComponent.new back_path: back_path %>
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import DateFieldController from './controllers/fields/date_field_controller'
import DateTimeFilterController from './controllers/date_time_filter_controller'
import EasyMdeController from './controllers/fields/easy_mde_controller'
import FilterController from './controllers/filter_controller'
import FormController from './controllers/form_controller'
import HiddenInputController from './controllers/hidden_input_controller'
import InputAutofocusController from './controllers/input_autofocus_controller'
import ItemSelectAllController from './controllers/item_select_all_controller'
Expand Down Expand Up @@ -59,6 +60,7 @@ application.register('copy-to-clipboard', CopyToClipboardController)
application.register('dashboard-card', DashboardCardController)
application.register('date-time-filter', DateTimeFilterController)
application.register('filter', FilterController)
application.register('form', FormController)
application.register('panel-refresh', PanelRefreshController)
application.register('hidden-input', HiddenInputController)
application.register('input-autofocus', InputAutofocusController)
Expand Down
8 changes: 8 additions & 0 deletions app/javascript/js/controllers/form_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Controller } from '@hotwired/stimulus'

// Connects to data-controller="form"
export default class extends Controller {
submit() {
this.element.requestSubmit()
}
}
16 changes: 16 additions & 0 deletions spec/system/avo/avo_cmd_return_to_submits_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

RSpec.describe "CmdReturnToSubmits", type: :system do
let(:admin) { create :user, roles: {admin: true} }
let(:project) { create :project }
before do
login_as admin
end # include TestHelpers::DisableAuthentication

it "submits form when cmd+enter is pressed" do
visit "/admin/resources/projects/#{project.id}/edit"
element = find("input[name='project[name]']")
element.send_keys [:control, :enter]
expect(page).to have_text "Project updated"
end
end
Loading