This is what I have in a template:
{{check-box isChecked=hasPhoneForSecureAlerts visibleLabelLoc=".t.settingscontact.label.phone" class="checkbox-inline narrow" testId="chk-phone"}}
This is what I have in controller for this property:
hasPhoneForSecureAlerts: Em.computed.bool('securePreferences.phoneLocalNumber'),
Let's assume, that originally this property is set to true and check box is checked, If I uncheck check box, this property is set to false and actually does not correspond to state of securePreferences.phoneLocalNumber.
To set it to initial value, when we are leaving this screen without saving, I just use in resetController at corresponding route:
controller.set('hasPhoneForSecureAlerts', controller.get('securePreferences.phoneLocalNumber') !== null);
Is this code correct? It actually works fine, but I am finding anywhere in Emberjs documentation something like that. Thanks!
I'm not 100% sure what you're code looks like but I think your problem is related to using Em.computed.bool. In this situation I would use Ember.computed.alias instead and I created a JSBin to demonstrate that it works. Let me know if you're still having trouble.
EDIT:
Ok, I think I realize now what you're trying to do. As you've noticed, this does work, but I would maybe rethink the way you're going about this simply because a checkbox is designed to be interacted with and what you are doing seems very unnatural. I would instead use a separate variable for your checkbox and make it a property. That way your property() function will run anytime the checkbox changes value. If the checkbox changes from checked to unchecked, then you can clear the phone number you have stored. I'm not sure what you would want to happen when the checkbox goes from unchecked to checked though. This is why I feel using a checkbox is a somewhat strange decision. Maybe you could create a minimal jsFiddle to demonstrate what you're intending to happen?
Related
So I have components with this code:
{{#summary-panel class="config-summary"}}
{{config-summary-body class="summary-body"
config=model.config
generateConfig="generateConfig"}}
{{device-summary-footer class="summary-footer"
config=model.config
generateConfig="generateConfig"}}
{{/summary-panel}}
Seems like every component placed in the {{yield}} of summary-panel is given the class config-summary which breaks the CSS layout of the device summary footer. The reason why I'm giving them classes here is because it seems that Ember puts the component in a div which breaks the layout I'm trying to do.
We have several config-panel-xyz components that are nearly exactly the same except for a couple changes here and there. So I figured I'd break them into separate components so they are more reusable.
I don't see why Ember would give every other component inside this the same clas as it just doesn't make sense. How do I make it stop doing this?
I also on a side-note don't like that I have to give the component a class when it will/should always have that class anyway. That seems kind of ugly to me, but I don't know how else to do it because it always gives the component a div that is defined in the actual {{component-name}}.
As I already commented to the question; what you claim is not the behavior of Ember.js. There must be something happening with the components you have designed.
Please check the twiddle I have prepared for you. As you can see, I have created the components with the same names as you and the classes assigned are as expected. You can check them out from your browser's debug console. config-summary is not being assigned as class to the other components. Please check this out and try to give more detail about your components if possible. You can even prepare a twiddle to illustrate your case; which might give us more insight about the problem.
I passed the result of this.store.findAll('something') to a component so I could create a dropdown control. Everything works great but I'd like to find the object I selected by reading this property.
Everything I read says its bad practice to inject the store into these components and since I already have the data in the property I thought it would be easy to read. However it's in an Ember model array that doesn't seem to be so easy to open because the array is deep down the stack.
I started heading down something like this.get('myprop').content... but I wondered if this was the correct way to do this. It seems I should be able to open them as the model they should be.
Any suggestions would be helpful.
it turns out the best way I could find to select my model was the 'peek' function. Not exactly what I wanted to do but it works.
Some of the comments below my initial question also work, but nobody ever actually added an answer so this is my answer. :-)
I am displaying a list of Document titles on the site's sidebar area. To achieve this I created a documents property on the App.SidebarController
Document = require '../models/document'
SidebarController = Ember.Controller.extend
documents: (->
Document.find()
).property()
module.exports = SidebarController
This works fine, when I create a new Document in my application, this sidebar property get's updated automatically and I don't know why. It works no matter what I put in the .property() function. e.g.
.property('Document')
.property('App.Document')
Can somebody explain how this works? What would be the correct thing for the property() function to observe?
So you are basically saying that is works, but you would like to know why.
Here is my guess: When your controller gets rendered, your computed property gets computed for the first time and an instance of an array is returned. When you create a new Document, i think this very same array is updated (= Document is added). So it does work despite the fact, that you do not specify a dependent key on property(). This is because the right array is already in place. As i said just a guess, but this seems like an understandable explanation.
And what would be the correct thing to do?
IMHO one should not use such Data Access methods directly in a computed property. Instead you should call this Data Access method inside a Route and then assign it to the controller. This way you make sure, that the find() method gets executed when needed.
I have the following problem with ember.
I have a table with a set of datas. I have an event that returns me the current element of the table. Then it opens another view by transitioning into a new state and writes the selected table data in a textfield.
click: function(e) {
var element = $(e.target).closest("td");
App.tee = element.text().trim();
var router;
router = this.get('controller.target.router');
router.transitionTo('newRoute')
As you can see I have some other routes in my router as well.
The last two routes(home and profile) are part of a nav-tab. They work perfectly beside I click on the table. Then i get the following error when i click on a tab: Uncaught TypeError: Cannot read property 'enterStates' of undefined
Ok i give it another try to explain what i wanted to do.
What i want to do is to create a table with some data (for example persons).
When i click on a specific person in the table the corresponding table-data should be shown in the textfields that appear below. Whenever i click on another person the textfields below should change to the informations of the current clicked person in the table. When i click "New" Button a more detailed Tabview appears on the right side with some additional informations. I was playing around with ember and so far i just implemented some of the views and the routing. Im stucked as i have tried to implement the event that updates the textfield below the table. It updates once but after it has transitioned into the new state(newRoute) nothing happens. I know the code is very raw, but it is just a test to understand how this works in ember.
Ok the solution was easier than i thought. The problem was not the state changing. It was more a problem of how to access the data and how to effect the change of binded data. I realised too late that i needed to understand how the variable access works in Ember and what exactly the App.initialize() method does. So App.initialize() initializes all Controller classes in the router. If you want to access any variables within a controller you have to get the access over the router like
{{view Ember.TextField valueBinding="App.router.tableController.person"}}
Secondly i wasnt familiar with the usage of the set and get methods in Ember and the difference between extend and create. I wondered before where ember instantiates my object.
So my problem had nothing to do with states it was just a totally misunderstanding of the ember framework. Im a noob thats all.
Ok, this is the first shot of the answer.
I think the main issue is just a typo gotoHome instead of goToHome in the template.
By the way I get rid of some deprecation warnings by using <button {{action }}></button> instead of Ember.Button.
There is some other warnings when I click on the table, because you are referencing some properties which don't exist.
here is the corresponding fiddle: http://jsfiddle.net/Sly7/rKw9A/25/
Since I don't understand how it should work exactly, I'm not sure of the overall behavior. I let you explain me the flow (by editing the question please).
Any other comment is welcome :)
Total Noob question here. My apologies for the simplicity, and I've skimmed hundreds of Ember-tagged posts here looking for an answer. But it appears to be too primitive for anyone to have bothered asking before...
I'm starting from scratch with Ember. I did Andy Matthews' EmberTweets tutorial, which worked fine. I'm trying to use that as a basis for my first Ember app, which is painfully simple; but I'm stuck on the most basic of steps. I appear to have a functioning controller, and am seemingly adding new objects to it successfully. But I cannot for the life of me get my view to render the properties of those objects. The basic view renders out, but not the data from the controller, which I'm just trying to access with a simple #each. I get no errors in any browser console.
Fiddle is here.
I've tried adding objects to the controller in three different ways in my example, to see if that helps. I can successfully access from the console the properties of the objects by inspecting the content array, or with something like FilterMenus.MenusController.content.objectAt(2).get('menu_name'). Apparently, the data is right where it's supposed to be.
But still nothing appears in my template when I try to render out any of the properties, such as: {{menu_name}}. What am I doing wrong, please?
As stated in the other answers, you have to declare your app as a global variable (by omitting the var).
Besides that, you are not calling this._super() inside your FilterMenus.menusController's init method. This is required to setup the Ember.ArrayController correctly, so modifying the content will work.
Besides these two issues, your code looks fine. Here's a working fiddle: http://jsfiddle.net/pangratz666/HPkHt/.
It seems like Ember's big problem with your code is that your Application is defined as a var so it can't be accessed from the template. Removing the var keyword helped.
For some reason though, that wasn't quite enough and I had to add a
this.set('content', []);
as the first line of your init function to get it to work. I've never had to do this before so I'm not sure if it's jsFiddle doing something. If anyone has some light to shed on this, I'd be keen to hear it.
Try the following:
Remove "var" from FilterMenus declaration:
FilterMenus = Em.Application.create();
Change the implementation of menusController.addMenu to be:
addMenu: function(menu) {
this.content.push(menu);
},
This got me the two menu names to show up after "Select Country" and the explanatory paragraph:
countries
countries2
Ember didn't seem to know what this.pushObject(menu); was. Pushing directly to the controller's content array will always work, though.