Last active
January 21, 2022 18:01
-
-
Save runspired/38fbefe880d3c17664c0225477ce0c01 to your computer and use it in GitHub Desktop.
Dynamic Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { tracked } from "@glimmer/tracking"; | |
import { set, action } from "@ember/object"; | |
export default class extends Component { | |
@tracked ads = []; | |
@tracked selectedAdType = null; | |
// this is just here for funsies | |
get json() { | |
return JSON.stringify(this.ads, null, 2); | |
} | |
adTypes = ["google", "facebook"]; | |
@action selectAdType(event) { | |
this.selectedAdType = event.target.value; | |
} | |
@action | |
addNewAd(type) { | |
const { ads } = this; | |
ads.push({ | |
type | |
}); | |
// alternatively to this "reset" import A and add | |
// to the ember array using pushObject instead of push | |
this.ads = ads; | |
this.selectedAdType = null; | |
return false; | |
} | |
@action | |
updateValue(ad, event) { | |
const { name, value } = event.target; | |
set(ad, name, value); | |
// we only need this to cause our json getter | |
// to update in the template since our simple objects | |
// dont have tracked properties | |
this.ads = this.ads; | |
} | |
@action | |
submitForm(event) { | |
event.preventDefault(); | |
// post it! | |
console.log("submitted", this.json); | |
// clear it! | |
this.ads = []; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { helper } from '@ember/component/helper'; | |
export default helper(function eq([a, b]/*, hash*/) { | |
return a === b; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment