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 boundsubmit=(action 'submit')action, just like{{f.submit}}does.- FontAwesome Icon: Replace
fa fa-savewith the icon class you want (e.g.,fa fa-checkfor a checkmark,fa fa-floppy-diskfor a save icon). Make sure FontAwesome is properly installed and included in your project (either via CDN or npm package). - Accessibility: Add the
aria-labelattribute to describe the button's purpose for screen readers—since there's no visible text, this is crucial for accessibility compliance. - Styling: Adjust the
classattribute on the button to match your existing design (e.g.,btn btn-defaultinstead ofbtn btn-primaryif 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
相关产品推荐
相关产品推荐

