Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9278935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:30:17+00:00 2026-06-18T17:30:17+00:00

I am looking for a solution to bind an object attribute that contains an

  • 0

I am looking for a solution to bind an object attribute that contains an array of string (representing an enum on the server) to a list of checkboxes. The binding should be two-way.

On the server, we have some enum defintion, e.g., Role with the values “ADMIN”, “GUEST”, “USER”. A user object may have several of thus roles, thus the user object in Ember is of the form

App.User = Ember.Object.create({
    roles: ["USER", "ADMIN"]
});

In the user administration, there should be a group of checkboxes. One checkbox per role. So, it is possible to select none, all, or several.

I know that there is the Ember.Checkbox view that can be used for this. What I am looking for would be a easy and generic view to handle any kind of enums as mentioned above.

Thus, the questions are:

  • has somebody a nice solution for this?
  • does anybody know a opensource project providing such extensions to ember?

Thanks in advance. // ph

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:30:19+00:00Added an answer on June 18, 2026 at 5:30 pm

    A generic way to handle a two way binding between an Ember object and Checkboxes can be implemented using plain Ember.js without the need of any plugins if you are willing to sync the enums on the server and the client manually (using AJAX or WebSockets). Note that Ember can update the list of options with Checkbox automatically after a sync.

    So henceforth, I will assume that you have am enum with roles as an Ember Array:

    App.Roles = [ "USER", "ADMIN", "GUEST" ];
    

    Then we will show the options available to the user in a CollectionView like this (the template is given below).

    OptionsView = Em.CollectionView.extend({
        contentBinding: 'App.Roles',  // Show a list of _all_ available roles
        userBinding: 'App.User',      // This points to the active user
        tagName: 'ul',                // Shown as a <ul>
        itemViewClass: Em.View.extend({
            userBinding: 'parentView.user',  // For convenience
            templateName: 'user-roles' // Defined later
        })
    });
    

    The template for each option is:

    <script data-template-name="user-roles" type="text/x-handlebars">
      <label> {{view App.RoleCheckbox 
                contentBinding="view.content"}} 
      {{view.content}}
      </label>
    </script> 
    

    Note that the use of <label> tag makes sure that the Checkbox’s click event is fired on clicking anywhere on the tag.

    Finally the App.RoleCheckbox is an extension of the Ember.Checkbox class which handles the checked property and click event to toggle the role:

    App.RoleCheckbox = Em.Checkbox.extend({
        userRolesBinding: 'parentView.user.roles', // Points to the roles of the user
    
        checked: function () {
            var userRoles = this.get('userRoles');
            return userRoles.contains(this.get('content'));
        }.property('content', 'userRoles.@each'),
    
        click: function (evt) {
            var isPresent = this.get('checked'),
                userRoles = this.get('userRoles'),
                role      = this.get('content');
    
             if (!isPresent) { 
                 userRoles.pushObject(role); 
             } else {
                 userRoles.removeObject(role);
             }
         }
    });
    

    An working example of this is: http://jsfiddle.net/BLQBf/ (Look at the console to see the log messages)

    Note that this is not completely Ember-esque, since the View is doing part of the job meant for the controller. Ideally, the click event would call a function on the RoleCheckboxController which would make changes to the User object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking after a solution to prevent object release in storyboard views. Here is
I am looking for a JS solution / design pattern that allows to call
I'm looking for solution how can run Ruby script without invoking it directly like
I'm looking for solution to extract some node from large xml file (using xmlstarlet
I'm looking for solution to get time to click on element using implicitlyWait in
I'm looking for solution for a in memory script cache, using Zend_Cache and zend
I am looking for a solution to display many items (10's of thousands) in
I was looking for some solution around here and I didnt find any correct
I am looking for the solution on hosting the videos of my site on
I am looking for a solution to: I don't have authorisation for installing an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.