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

New Component: {{fieldset-editor}} #19

Open
nadnoslen opened this issue Dec 28, 2017 · 0 comments
Open

New Component: {{fieldset-editor}} #19

nadnoslen opened this issue Dec 28, 2017 · 0 comments

Comments

@nadnoslen
Copy link
Member

I've seen a pattern in my form-driven components.

  1. For almost every model that I want to edit I create a new form component that is an extension of the twbs-form component in this package. This is typically extension of the twbs-form. I feel that form should be responsible for persistence only.
  2. I feel a fieldset element (or editor) can be used to toggle between the read-only and editable version of the model in question.
    1. The following actions can be pushed into the component: cancel, destroy, new, and save.
    2. The template will accept a block that should effe

Component JS

import Ember from 'ember';

export default Ember.Component.extend({
  /**
   * REQUIRED.
   * The action to fire when the form is reset/cancelled.
   */
  actionCancel: '',

  /**
   * REQUIRED.
   * The action to fire when the model is asked to be destroyed.
   */
  actionDestroy: '',

  /**
   * REQUIRED.
   * The action to fire when the new plus button is pressed.
   */
  actionNew: '',

  /**
   * REQUIRED.
   * The action to fire when the form is saved.
   */
  actionSave: '',

  /**
   * `true` shows the edit for.  `false` hides the form (default).
   */
  'editor?': Ember.computed.notEmpty('modelInstance'),

  /**
   * REQUIRED.
   * The model instance to be edited.
   */
  modelInstance: undefined,

  /**
   * Is the model not yet persisted (e.g. brand new).
   */
  'new?': Ember.computed.bool('modelInstance.isNew'),

  tagName: 'fieldset'
});

Component Template

<legend></legend>
{{#if editor?}}
  {{!-- some sort of form here --}}
{{else}}
  {{yield (hash new?=new?))
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant