You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ember框架实现FontAwesome图标触发表单提交功能

Got it! To replace the default submit text button with a FontAwesome icon in your Ember form, you can ditch the {{f.submit}} helper and use a standard <button> element with type="submit" (so it triggers the form's submission action) and embed your FontAwesome icon inside it. Here's how to adjust your code:

Modified Code Snippet

{{#with (changeset company validations) as |changeset|}} 
  {{#form-for changeset submit=(action 'submit') as |f|}} 
    <div class="card-header bg-primary"> 
      <div class="row"> 
        <div class="col-sm-6">
          <!-- Your existing header content here -->
        </div>
        <div class="col-sm-6 text-right">
          <!-- Replace {{f.submit}} with this button -->
          <button type="submit" class="btn btn-primary" aria-label="Save company changes">
            <i class="fa fa-save"></i> <!-- Use your desired FontAwesome icon class here -->
          </button>
        </div>
      </div>
    </div>
    <!-- Rest of your form fields here -->
  {{/form-for}}
{{/with}}

Key Notes:

  • type="submit": This ensures clicking the button triggers the form's bound submit=(action 'submit') action, just like {{f.submit}} does.
  • FontAwesome Icon: Replace fa fa-save with the icon class you want (e.g., fa fa-check for a checkmark, fa fa-floppy-disk for a save icon). Make sure FontAwesome is properly installed and included in your project (either via CDN or npm package).
  • Accessibility: Add the aria-label attribute to describe the button's purpose for screen readers—since there's no visible text, this is crucial for accessibility compliance.
  • Styling: Adjust the class attribute on the button to match your existing design (e.g., btn btn-default instead of btn btn-primary if that's your theme's default button style).

This approach keeps the form's submission behavior intact while giving you full control over the button's appearance with FontAwesome.

内容的提问来源于stack exchange,提问作者Robin Steiner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:22:31