How to instruct an element to update it's model from outside - polymer

In my polymer app, I have one element containing a list of items, and another element with the form to CRUD these items.
After inserting a new item from the form-element, how can I instruct the other element to re-pull the model data ? (and thus redraw the list items)

I'm using Firing custom events.
Suppose core-ajax is used for inserting a new item, on core-ajax response fire the event 'insert_done'.
List element should catch that event and get the items, this time with the new one in.
...
This is some general answer, but you can share some code for more specific answer.

Either lookup the list using a dom query and call an update method. Or, bind a variable that is used to notify the list of the change. Use an observer, in the list element, to execute the update code when the property value is changed by the form element.

Related

Properly instantiating a template instance so that everything is present (model data, filters, event handlers)

I'm a bit of trouble instantiating a custom template, and making all the bindings work. My custom element which has to do this is quite similar to polymer/core-list, with a few differences. Like core-list, the parent adds the element invokes my custom element, and adds a template as its content, as seen here.
Unlike core-list, the element adds an id to this template, and creates a few templates which refer to that one, as seen here. Finally, when the time comes, these new templates are used to create a few elements and add them in the dom.
That's all fine and good, and mostly, it works correctly. The model data is used to fill the resulting element correctly, and the default filters work, thanks to the PolymerExpressions used as a bindingDelegate. However, event handlers do not seem to work.
I don't know whether the handler function can't be found in whatever scope is used, or something else is at play here. The only thing I currently know is that the on-tap attribute value is empty when I look at the polymer-icon-button through the web inspector. With a very similar usage using the core-list, the event handler works. The web inspector there shows the polymer expression as the value of the on-tap attribute. And both handlers are defined in the parent element which contains the invokations of core-list and my element, and the templates which are passed to the corresponding contents.

how can I code different events for Add to Listview and Reorder Listview in Winrt

I am having trouble getting code to fire when a listview has items reordered. I created an event handler for collectionchanged, but that fires when an item is added. I want it only to fire when it is reordered, but reordered in Winrt is a combination of remove and add.
The more general idea of what I want to do is create two listviews of items, where the first listview's items rearrange if corresponding items in the second listview are reordered by the user using drag and drop. I'm pretty close to getting it to work. I have id numbers for elements in both lists.
First, make sure you are using an observable collection.
Second, read this: XAML/C#: What event fires after reordering a gridview?
Best of luck!

Connecting UI Elements in Google Apps Script (TabPanel - UiApp)

I've already asked a similar question, but I really can't figure out how to connect these elements together. I'm still not very good with Handlers, and I guess my question is:
How can I access UI Widgets (and their children) while outside of the doGet() function?
My use case is this: I have a list of projects/IDs. I have all the data I want based on the ID that will populate the Project Details tab of this application. I created 'unique' Buttons for each of these Projects, and threw them into a Grid. Now, I want to generate the Project Details (detailPanel) Widgets specifically for each Button if/when it is clicked.
I have the Project ID attached to each Button (uniquely) through a Hidden, but I can't seem to attach the Project Details tab (detailPanel) to the Button so that, when clicked, I can set the values for the TextBox, DateBox, ListBox, etc. Widgets of the detailPanel.
I think I'm missing something obvious about this. I want to avoid attaching each child Widget of the detailPanel as a callbackElement of the Button at all costs. There are around 40 elements (I've lost count), and it seems really inefficient. I'm almost sure that if I can add one Widget as a callback element, that I get access to all child Widgets. But I tried, and that doesn't seem to be the case.
Here is the link to the public UiApp, which shows the UI. And the sister Script Project (uneditable).
You dont need to add callback elements that you will write to, callback elements are only for reading their data. If the detailspanel id is dynamic have a hidden that has its id stored inside and pass it to the handler. from your handler you getelementbyid and set its data.

Why is directly manipulating the Rails form params hash considered code smell?

I have a Rails form with a parent model and nested attributes for potentially multiple children of another model.
The child model has an attribute which is manipulated in logic as an array, but is serialized to a YAML string using the Rails built-in serialize method.
Within the form, I display each individual member of the array so that the user can selectively delete members.
The problem happens when the user destroys all members. The form will not pass any value for the param to the Rails controller and when the UPDATE action is called, it ignores the attribute since there is no key for it in the forms params hash. This is of course a known problem with things like checkboxes, so Rails automatically puts 2 checkbox HTML elements for each checkbox, one hidden that only processes if the checkbox is checked off.
I'm not dealing with checkboxes here but rather hidden input text fields.
The solution I've implemented is to manipulate the params hash directly in the UPDATE action of the controller, like this:
params[:series][:time_slots_attributes].each { |k,v| v[:exdates] ||= [] }
Is this considered code smell?
Should I instead add an extra hidden field that is disabled and only gets enabled when the user removes the last member? This solution works as well, but it seems clunky to me.
This is dealt with in the NestedAttributes module by allowing a "_destroy" parameter to trigger a destroy call for that particular nested attribute:
http://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for.
If you're not using nested attributes (which you probably should be, it's pretty neat in a lot of situations) then yes, you'll have to handroll something yourself, by working out which values should have been present and doing something special with those.
This is far from an exhaustive answer...but after thinking about this problem, one issue I can see is that if future forms are built that leverage the same UPDATE action, unexpected behavior will occur, which violates the principle of least surprise. If at a later time a second form is built which does not expect to change values for the exdates attribute (since it does not pass them), the UPDATE action will write an empty array into the attribute anyway.
I've decided to solve this issue by adding a single hidden form field with a true boolean value and later to check for this value before setting all time slot exdates to an empty array. This way, if a future developer creates a new form that leverages the UPDATE action of the series controller, they won't get the unexpected behavior of their exdates being set to empty arrays. If they want to process exdates in their form, they need to have the same hidden form field with a true value. This seemed like a simpler solution then adding a class and table for exdates, migration, and the AR associations and adding another layer of nested attributes so that I'd have not only a parent and children attributes, put a parent, children and grandchildren. This solution is a bit like the Rails hack for dealing with checkboxes with a second hidden checkbox field in the form.

Disabling Datagrid selection in flex

i have an array list of data which i am showing in spark data grid.
once i select an idem and click on a button that i have linked with datagrid it adds a panel on screen. I want to disable this selection i-e to tell that this item panel have already been added. Any ideas how can i do that?
best Regards
Try this.contains(child:DisplayObject) It Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.
I think there's a .disable() function on datagrids, or you can use return false; so that it won't proceed.