I hope to express myself with appropriate terms.
I have three entities: customer, country, state. Between country and state, there are two relationships. So I can create a number of countries and select one of these I can create a number of states that belong to it.
For creating the interface of the entity "customer" I put threeNSPopUpButton's:
The first selects the country,
The second shows the states related to the selected country.
The last shows the zip code related to the chosen state.
My problem is that I can not pass data through the chosenNSPopUpButton entity "customer". The NSPopoUpButton works by binding:
Content (bind to:country, arrangedObjects),
Content Values (bind to:country, arrangedObjects, model key:country),
Selected Index (bind to:country, selectionIndex).
What can I do to ensure that the data selected by the three NSPopUpButton's are recorded in the appropriate fields of the entity "customer"?
It would seem that using 3 popups may work with your problem here, as you can return the int for each selected item, and then pass that information on to the next button press.
So, when they press 'country', return back the country id, and put that in your customer entity.
Then, when they press state, pass the country to this popup, and show the states, and pass the state id back, and do the same for city.
This way you don't have lots of managed objects around, as you really don't need the data, you just need the id, and perhaps the name, to show to the user, and these can be passed back in a notification back to your controller.
Related
I'm wondering if I can store a different value in the redux form FieldArray than what's displayed on the frontend.
Using the example from the docs: Each club has a club name and consists out of various members. I want to introduce another model called group which also consists out of at least one member.
I combine the firstName and lastName field to one field and let the user type in either the members individually OR the user can type in a group name which then fills in all members of that group but on the frontend, only the group name shows up, instead of each member name individually.
Currently, I allow this and then before I post the values to the server, I fetch the members of that group via a get request and then switch the group name for the member names.
I'm wondering if there is a more elegant (and faster) way to do this? I was looking at the parse method but it changes the value right away and doesn't let me display it how the user typed it in.
I have an Access form that lists all records in a table. One column in that table refers to a 'device' table, which then has a foreign key reference to a 'brand' column. In the form, the brand name + device name are displayed due to some magic in a combo box for every row.
The question: how can I sort this form by the brand name, while still retaining the ability to create new records? This is my current query:
SELECT ehs.*
FROM ehs, brand, device
WHERE brand.ID=device.brand_id AND ehs.device_id=device.ID
ORDER BY brand.brand_name, device.model;
Apparently (and understandably), you cannot add records when the query has a join in it. What would be a better approach to sorting the list?
You can create a form that has a foreign key in the query that allows adds and updates. I've just done this in Access 2010 to confirm.
It's possible that some of the magic you mentioned with the combo boxes has broken the ability to do so.
Note: I've just noticed I've used DeviceName where you've used model - you'll need to adjust the SQL below.
There are some tricks, though:
Make sure all of your tables have primary keys (hard to avoid in Access)
Make sure all your foreign keys are indexed (so brand_id in device table, and device_id in ehs table) - duplicates ok.
Use the relationships diagram to draw the relationships between these tables
I then created a query - I just used the query designer, so Access' interesting brackety arrangement is all its own doing:
SELECT ehs.*
FROM (Brand INNER JOIN Device ON Brand.brandID = Device.BrandID) INNER JOIN ehs ON Device.DeviceID = ehs.DeviceID
ORDER BY Brand.Brandname, Device.DeviceName;
If you view that in a data sheet view you should be able to add a record. That's important, if you can't there's a problem, if you can then we're on the way.
If this works, then I'd suggest create a new form based on this query and verify that the new form allows you to add records. This new form is basically going to have an id number for device_id. So you'll have to type a number to make it work.
The trick you're going to want to perform is, and I'm guessing the thing that's causing you problems:
To have a "brand" drop-down that you choose a brand, which then limits the options for the device drop-down.
That's REAL tricky (and I'm afraid I'm somewhat rusty in Access, and it's not in the question, really).
What you CAN do, easily, instead, is have a drop-down for device, that includes the brand name, and sort that appropriately.
I added a combo box to the form. The wizard takes you through using a table or query, I just chose the device table (we'll tweak this later), and the fields - you need device_id model and brand_id, and what to display (model and brand_id - we'll tweak it) and it hides the primary key. When it says "do you want to save it for later or store it in this field, choose store it in this field and choose device_id (which is in the ehs table).
When the wizard completes, click on the new combo box, and get the properties for it. Switch to the Data tab, an there's a builder [...] button next to RowSource. Click that, you get a query builder. Add the Brand table and show the brand_name field and hide the brand-id field. (We just chose that so the combo box has two columns). Sort as you like.
When you close it, it will ask you if you want to save it, so say yes. Your SQL will be something like (with appropriate field name changes because of my mistake):
SELECT Device.DeviceID, Brand.Brandname, Device.DeviceName
FROM Brand INNER JOIN Device ON Brand.brandID = Device.BrandID
ORDER BY Device.DeviceName;
Your form should now have a combo box that shows the device name when not selected, and device name and brand name when you select the drop-down.
You can then delete the original device_id text box from the form.
And you can also add the brand name to the source query and add it as a text field on your form, so you can see the brand next to the device, even when it's not in the drop-down.
The primary query for the form can be:
SELECT ehs.*, Brand.Brandname
FROM (Brand INNER JOIN Device ON Brand.brandID = Device.BrandID) INNER JOIN ehs ON Device.DeviceID = ehs.DeviceID
ORDER BY Brand.Brandname, Device.DeviceName;
You can add BrandName as a text box - you don't need devicename (model) because this shows in the combo box.
And you should still be able to add records.
So, not ideal, but a lot simpler than coding up a bunch of VBA, which is where I think you'd need to go if you wanted to separate your combo boxes (not sure), especially as that's not the original question anyway.
I suggest you do each step and verify that it's still working at each stage.
Good luck.
In my application I use two entities.
1) City
2) Shop
They have a relationship one-to-many
For example:
- Barcelona:city
-- Decathlon:shop
-- Salewa:shop
- New York:city
-- Puma:shop
-- Nike:shop
First step:
Via the dropdown list the user selects a city:
It raises the event by changing the value of the list. At this point the javascript code must request and obtain all the stores for the selected city.
Second step:
Show the second drop-down list with the values of stores for the selected city.
Ok. Now my questions:
1) How to make a request to the data model? (I am interested not so much JS code but backend architecture. Should I do API or rather request data from the controller to the same page?)
2) How should look the part of code implements the class of this form?
1) Request. The best way is a JSON response via a separate controller. Everything is very simple here.
2) Form. This question is more interesting. The City dropdown should be a not-mapped field of City Entity. The Shop field should be a simple Shop entity field with no choices if you don't have default city in your form ('choices' => array() in field options), or make it select all default city shops by the query_builder option. When you get a response from the backend after selecting a city, just append all possible options to the shop dropdown which consist a shop ID as their value.
There are many schools of thought about implementing this but I am personally a big fan of sending the whole relation to the view and managing the switching with javascript, so something like this would do:
return $this->render('YourBundle:Controller:index.html.twig', array(
'cities' => $cities_with_shops_json,
'form' => $form->createView(),
));
The javascript part is just capturing the event but there are many examples in google.
http://javascript.about.com/library/bldydrop1.htm
One advantage of this is avoiding the ajax call every time the user click on the select.
I have report UI with a small form at top where the user looks up a person by name using an Auto-Suggest textbox, and I set a hidden ID field when they select one. They then enter a start and end date, and hit submit to load a report below. The report data is fetched using the Person's ID, and the date range as a Backbone route. I can also show the person's name in the report header since I have it from the Auto-Suggest lookup.
The problem is, if someone bookmarks a report (a nice feature to have), I'd like to repopulate the form (which shows the person's name) and the report header.
So, currently I have one route ('id/startdate/to/enddate') that sometimes is triggered by an already populated form model, and sometimes is triggered by a bookmark/refresh and needs to repopulate the form model from route data and server-side data.
How would you model this? I was going to have a model bound to the form:
{ id: 234, name: 'Bill', startDate: '1/1/2011', endDate: '1/1/2012' }
But I am struggling with this idea of sometimes needing to fetch the name and populate the form, and sometimes already having a populated form (and name). Feels like there should be a better design for my Backbone views/models/routes.
You can populate your Model from the router by triggering a message with the name, startDate etc parameters that the Model will listen to.
The same thing can be done in the View that sets the data on the Model. So, regardless of where you get the information from (View, Router), your Model would correctly hold the state.
Then your Form View could listen on changes to its Model, re-rendering itself with pre-filled information on Model change.
Hope it helps.
I have an example application I'm working on to help me learn about Core Data. In this application I created a model consisting of the entities "Friend" and "City". The application list my friends and which city they are from in an NSTableView. In this table view I would like to have the City column be an NSComboBoxCell with a list of the cities. I got this far... now for the problem:
When I select the city from the combo box, the application takes the value of the selected city name and applies it to the name of the city the friend is currently from. Instead, I would like the application to actually change the city the user is from and not the name of the city... That's a bit confusing of a question, so here's an example: starting with a list of friends like
Andy Asheville
Francois Montreal
Jeff Asheville
If I use the NSComboBoxCell to change the city for Andy from Asheville to Montreal, the application actually changes the name of the City Asheville to Montreal, so the result looks like:
Andy Montreal
Francois Montreal
Jeff Montreal
There are still two distinct cities in the application, but they now both have the name Montreal.
This all makes sense to me given the way I set up my bindings. I bound the value of the city table column by setting Model Key Path to "city.name" and the Controller Key to arrangedObjects, which contains the list of friends. So of course, when the value of a cell changes it modifies city.name. So then my question becomes what's the proper way to do this so that the city changes instead of the city name?
The purpose of NSComboBox is to "allow you to either enter text directly (as you would with an NSTextField) or (...) select from a displayed list of items". (taken from Apple Cocoa Ref).
So The combo box is a glorified NSTextField. The behavior you expect is more in line with the NSPopupButton.
As you noted, the NSComboBox bindings change the name value of the current City, but do not alter the object relationship, hence they change the name of the current city represented by the relationship (which then gets "propagated" to other Friends pointing to the same City entity).
If you look at the available bindings for NSPopupButton you'll see the difference. You probably want to use the NSPopupButton(Cell) to assign Cities to Friends, with some sort of "on the side", NSTableView-based editor to manage your city names — which are really two distinct tasks.