Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karellm/e4e5b5a08eb78927680e57a872f29c82 to your computer and use it in GitHub Desktop.
Save karellm/e4e5b5a08eb78927680e57a872f29c82 to your computer and use it in GitHub Desktop.
One way checkbox
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
worksOk: DS.attr('boolean'),
doesNotWorks: DS.attr('boolean', { defaultValue: false })
});
import Ember from 'ember';
import Changeset from 'ember-changeset';
export default Ember.Route.extend({
model() {
return this.store.createRecord('my-model');
},
setupController(controller, model) {
const changeset = new Changeset(model);
controller.set('changeset', changeset);
return this._super(...arguments);
}
});
<h1>Works</h1>
<p>
{{one-way-checkbox
checked=changeset.worksOk
update=(action (mut changeset.worksOk))
}}
Works Ok
</p>
<p>
Model value: {{model.worksOk}}
<br>
Changeset value: {{changeset.worksOk}}
</p>
<h1>Does not work</h1>
<p>
{{one-way-checkbox
checked=changeset.doesNotWorks
update=(action (mut changeset.doesNotWorks))
}}
Does not work
</p>
<p>
Model value: {{model.doesNotWorks}}
<br>
Changeset value: {{changeset.doesNotWorks}}
</p>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.11.0",
"ember-changeset": "^1.2.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.11.0",
"ember-testing": "2.11.0"
},
"addons": {
"ember-one-way-controls": "*",
"ember-changeset": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment