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

Pass optional content to the inputComponent #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eelke
Copy link

@eelke eelke commented Dec 21, 2017

In dynamically generated forms (ie. from Model or other data) this allows the inputComponent’s options to be dynamic too.

In dynamically generated forms (ie. from Model or other data) this allows the inputComponent’s options to be dynamic too.

Signed-off-by: Eelke Feenstra <dev@eelke.net>
@jbandura
Copy link
Owner

I'm sorry for this very late response (was in a middle of job change), but you could you provide a use case for that? :)

@eelke
Copy link
Author

eelke commented Mar 26, 2018

Sure! In my use case I needed something like the mr-ms-input, but required more flexibility as the component became part of a sort of form building tool.
So, imagine the options for your mr-ms-input would come from loaded data or a model. Instead of defining these in the handlebars file, they could be added through the handlebar attribute, and we can loop through the options.

My input template looks like this:

  {{#each content as |option|}}
    {{#if option.value}}
      <button type="button" class={{if (eq value option.value) 'selected'}} {{action 'clicked' option.value}}>{{capitalize option.label}}</button>
    {{/if}}
  {{/each}}

And the component code stayed pretty much the same

import Ember from "ember";
import Component from "ember-component";

export default Component.extend({

    classNames: ["form-sex-input"],
    classNameBindings: ["hasSelection"],

    readonly: false,
    hasSelection: Ember.computed.notEmpty("value"),
    value: null,

    actions: {
        clicked(val) {
            if (this.get("readonly")) return;
            this.set("value", val);
            this.get("update")(val);
        }
    }
});

I hope this makes sense and there was not already a better way of doing this ;)

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

Successfully merging this pull request may close these issues.

2 participants