Dynamically loaded html doesnt have access to viewModel - aurelia

I will give a simple case scenario to illustrate my problem. I have a view and a viewModel. The viewModel has a method redirect(). After my view and its model are loaded I dynamically add a html button to the page and use click.delegate to link to method redirect() in viewModel. But clicking the button doesn't call the method. How to fix this.
If binding is not a possible workaround

You cannot add new bindings to the DOM through DOM manipulation because they will not be bound properly.
Instead you should either conditionally show it -
<button click.delegate="redirect()" if.bind="showRedirect">Redirect</button>

Related

What is the best practice of propagating variable value in Yii

I have a menu which pass parameters when a user click on one of the items menu.
When a user click an item menu, a view is lauched and call another view which call another view...
Can you tell me what is best practice on passing parameter from view to view.
Do I have to pass from view 1 to view2 and so on ..(as I did but I dont find it very clean) or it is another better way to do this.
I must say that I cannot put the value at the tpp of my controller because at that moment I do not know which menu wil be clicked.
Thanks for your reponse
I assume you are talking about views inside other views http://www.larryullman.com/2011/02/15/rendering-view-files-in-yii/ otherwise the question does not make a lot of sense.
The view has access to all the controller variables. So you can define a variable for the controller and you will be able to access it all the time in any of the nested views with $this->variable. You can actually put it at the top of the controller because that never changes while you are creating the views. That is 1 request, it should not change while you are processing the views.
If you are trying to make some ninja html, creating html with ajax based on what multiple menus the user clicks you can always save something in the session/cache and use that part but cleaner is to pass the argument through the entire process.

Cocoa : Detect changes to any form element

I have a form built in interface builder.
Now I want to receive a notification when any element that is a child of a particular view is changed (be it text, or the select element, or a checkbox, etc).
Basically I want to know whether or not the form is "dirty" (changed).
How can I accomplish this?
One simple answer is to connect those UI elements which might change the value of the data model to an IBAction in the parent view controller. In that IBAction you can decide if you want to save the data, present a dialog, etc.

Show new view in Ext.tab.Panel

I have Ext.tab.Panel with few items. One item is login panel of type Ext.form.Panel.From controller I call Ext.Ajax.request to login. From callback method i would like to show new view(logged in). I mean on the same tab replace tab content login form view with new view (Ext.List/Ext.Panel)
Can someone guide me how to make it? I did't found correct functions in Ext.tab.Panel docs.
Thanks
setActiveItem method for TabPanel (http://docs.sencha.com/touch/2-0/#!/api/Ext.tab.Panel)

Difficulty in deciding where to put the code in yii view helper

I'm new to yii development.
In my system I'm trying to create a submenu system. The submenu will be shown based on the
controller. The submenu will be separate views, that I'll load in main layout.
I want to separate the logic of loading the submenu view from the main layout. But, I'm not sure where to write it.
Does Yii has view helpers like in RoR. Or, should I write it as a component?
Please give suggestions.
Thanks.
I'd just create a component for this, and instantiate that with the relevant menu options from the controllers. If present in all controllers, implement support in a BaseController and just set up an array of items in the child controllers.
Your default generated Yii application has a parent Controller in protected/components/Controller.php. If you need to access additional parameters in layout, add public properties to Controller, set them in your child controller, and use them in your view/layout files.
In your case, add a function to this parent Controller that returns a rendered submenu (with a renderPartial call for example) and call this function from your layout.

Passing control as command parameter in Silverlight and MVVM Light

I am trying to get my head around MVVM and the Navigation-based project template in SL4. At the moment I am trying to move the ContentFrame_Navigated event handler into the ViewModel. Basically this event handler checks each hyperlink button in the menu bar against the current page and adjusts the style accordingly. To do this it seems I need to pass the EventArgs as well as another object. I see MVVM Light has the PassEventArgsToCommand bit, but what about passing another object/control? In this case it's the StackPanel hosting the list of menu item hyperlinks. I'm just getting my head around the MVVM concept, what's the best practice in this case?
Cheers,
Dany.
With MVVM you have to think more abstract. You are not daling with a list of HyperLink elements, but with a list of Navigation Targets. I.e. you should separate the presentation (HyperLink elemen) from the data (the URL, the Title, whether the item is selected or not, etc.). You now hold the data in a list on your ViewModel (normally you would see this data as the ViewModel of your Hyperlinks, and name it accordingly). The items are held in a ObservableCollection so that you can track changes if a item is added etc.
To display this list you can use a class inheriting from ItemsPresnter (e.g. a ListBox) and use binding to set the properties. Now you navigate to a page you can set the IsSelected property of the relevant item in the list, resetting all other IsSelected properties.
As the navigation targets can be seen as a global collection, you can also hold it in a property on the ViewLocator, so that all Views and ViewModel can access this list, and setting the IsSelectedProperty is applicable to all Views. This global collection represent you navigation state.
And, BTW, the EventToCommand, the RelayCommand, and the Command attribute ony support one parameter. Furthermore, from experience I can advise you that it is not good practice (although you obviously can do it) to mix View objects, such as EventArgs, or elements and your ViewModel.
one solution is to put the menu items the ViewModel, and the View can bind this list.
then the View wouldn't need to send the menu items to the ViewModel