Wednesday, May 2, 2012

set explicit source update while using data context

I need to update the binding source object with the control values only during a button click event.



But as my top level has datacontext being set, it's updating the source object whenever the control values change... Is it possible to set explicitly to update it during that event only keeping the datacontext as it is?





Share session (cookies) between subdomains in Rails?

I have an app setup where each user belongs to a company, and that company has a subdomain (I am using basecamp style subdomains). The problem that I am facing is that rails is creating multiple cookies (one for lvh.me and another for subdomain.lvh.me) which is causing quite a few breaks in my application(such as flash messages being persistent though out all requests once signed in).



I have this in my /cofig/initilizers/session_store.rb file:



AppName::Application.config.session_store :cookie_store, key: '_application_devise_session', domain: :all


The domain: :all seems to be the standard answer I found on Google, but that doesn't seem to be working for me. Any help is appreciated!





Nested Async Javascript

I am using the technique specified http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ to load external javascript when the window.onload() is triggered. But if the script itself contains some registration of load event handler then they might not get called as the event has been (somehow) passed. In order to confirm, I added the following code to the external javascript file that is loaded as mentioned above:





(function() {
if (window.attachEvent)
window.attachEvent('onload', alert("ok"));
else
window.addEventListener('load', alert("ok"), false);
})();



This alert actually appears which make me think, whether the onload is called twice or does loading javascript means loading the script, running its "global" part and then moving on to the next listener. In the latter case, if another listener is added to onload event while running its "global" part then this behavior is correct. But I am not sure of this and would appreciate if someone more experienced could clarify/confirm it.





Symfony2 Forms - Cannot add/remove entities from a collection

I have a form for a "Person" entity that has a collection of "Nicknames".



I have implemented this following the guide in the cookbook (http://symfony.com/doc/current/cookbook/form/form_collections.html)



When I create a new "Person" I can add "Nicknames" as expected successfully.



Using a similar form I have an edit page. On the edit page I have set up the front end in the same way as the new page.



On the edit page, I can edit the existing nicknames and the other simple fields successfully. However, when I submit a new "Nickname" (or try to remove one), it does not work.



I have var_dump()'ed the request object before it is binded to the "Person" and I have var_dump()ed the "Person" object after binding. The request does have the "Nicknames" collection passed correctly. However, they are not being binded to the Person at all, despite the fact that everything is the same as the new page. Further, I can still edit the existing Nicknames so it is working on that front.



I cannot for the life of me figure out why Symfony isn't creating these new Nicknames or adding them to the Person as it should. I have looked around and searched but everything just confirms that it should be working - but it isn't.



Heres the entry for the Nicknames on the Person form type:



->add('nicknames', 'collection', array(
'type' => new NicknameType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
'required' => false
))


Nickname type only has one field - "nickname" and its a text input.



Any help? Thanks for reading.



EDIT:



Here is the update action (changed Person to Player):



public function updateAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();

$player = $em->getRepository('SCDBAppBundle:Player')->find($id);

if (!$player) {
throw $this->createNotFoundException('Unable to find Player.');
}

$editForm = $this->createForm(new EditPlayerType(), $player);
$deleteForm = $this->createGenericIDForm($id);

$editForm->bindRequest($request);

if ($editForm->isValid()) {
$em->persist($player);
$em->flush();

return $this->redirect($this->generateUrl('admin_player_edit', array('id' => $id)));
}

return array(
'player' => $player,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}


I realize that to actually persist removing nicknames I need to change the code to persist. I'm not even worried about persistence right now, because the main issue is that after I bind the request to the Player form, the $player object does not contain the updated Nicknames collection.





Flex: implementing TextInput restrict in spark table gives error

I'm creating a Flex table in which one column is editable. I want to restrict the user's input to certain characters. The following code gives an Could not resolve <s:itemEditor> to a component implementation error. Anyone know how to resolve this?



....
<fx:Array>
<supportClasses:MyColumn ... />
<supportClasses:MyColumn editable="true" ...>
<s:itemEditor>
<fx:Component>
<s:TextInput restrict="0-9a-zA-Z"/>
</fx:Component>
</s:itemEditor>
</supportClasses:MyColumn>
<supportClasses:MyColumn ... />
...
</fx:Array>
....




Binding to DataGridTemplateColumn using style applied within DataTemplate?

I have a ComboBox that composes a DataTemplate, and I'm having trouble binding its IsEnabled property to the IsReadOnly property on the templated DataGridTemplateColumn.



I've been receiving the following error in my VS output window:




'IsReadOnly' property not found on 'object' ''ContentPresenter'




ComboBox style:



<Style TargetType="{x:Type ComboBox}" x:Key="ProficiencyColumnComboBoxStyle">
<Setter Property="IsEnabled"
Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=IsReadOnly, Converter={StaticResource BooleanOppositeConverter}}" />
</Style>


I believe the problem is with how I specify the RelativeSource intended to identify my DataGridColumn. I've tried:




  • RelativeSource={RelativeSource TemplatedParent}


  • RelativeSource AncestorType={x:Type DataGridColumn}


  • RelativeSource AncestorType={x:Type DataGridTemplateColumn}




I've tried adding other setters to this style, and they do take effect, so I know the style and DataTemplate are being applied to the controls.



P.S.



I've used this same technique to bind another ComboBox within a DataTemplate to a property on the parent DataGrid of its templated columns. The difference is that here I'm using a converter, and trying to bind to a property on a column (instead of the grid.) However, even if I remove the converter from the above style, no binding takes place.





Convert listBox.SelectedItem to PointF

I have an item in my listbox;
I want to take it and convert it to PointF so that I can compare it with a list of pointF.



Example)
var selection = listBox3.SelectedItem ; // like "{X=18,Y=48.10001}"



PointF p1 = (PointF) selection;



//now when that item has been selected and converted to float point, I want to search and find it in list called optFlowPoints to see if that points exists



PointF drawPointEst=optFlowPonits.Find(p=>p.Equals(selection));



So there are two problems:




  1. how to convert selectedItem to PointF

  2. how to write my lambda expression to find the match