Wrong Item Id in Collection - forms

I have collection field type in my form. And I have problem with Id of a field. When page is loaded for example I've got three items in my collection. In this case they should have ID's 0, 1 and 2 but They've got 4, 5, 6....
<input type="text" id="form_crm_contact_person_contactPhone_4_value" name="form_crm_contact_person[contactPhone][4][value]">
Later when I add new item It has Id 4, and it would be okey when previous items would have correct Id's. But in this case new item is updating this old item instead of being a new one - when the form is saved...
Any ideas what can be wrong ? I have to say that in other collection in my application everything it's okey... Rest start with zero.

Related

What is the correct way to save a list of items in a web form?

There is some form in a web form. It contains the list of items that use can edit, remove and change.
When the server receive the list of items, it should update existing items, create ones and remove the deleted ones.
I only know the naive and quite ugly approach:
When server receives the list of items from a client, it gets the actual list of items from the database
Pass round the received list of items:
2.1. If element has the ID and database has the element with this ID, this element updates
2.2. If this element doesn't have ID or database doesn't contain element with this ID, this element creates
Delete all items, that were not in the received list (marked as deleted)
The updated list of items are returnded to the client (with new IDs), and client displays them
I feel, that there is more elegant solution, and, propably, established for this task.
I had the same challenge and i solved it like this:
1-First when you load the page, create a list made up of id and data.
2-then the user fill the data.
3-those items that user doesnt fill should be deffault value.
4- then retrive the list from database and delete it and put the updated list
Hope this helps

Where are form elements rendered in Drupal 7? I'm looking for why the sixth item in a select option list doesn't get rendered

I have Drupal 7.58 site where there's a select list with 15 items that come from an entity reference. When I put a debugging statement into form_type_select_value in includes/form.inc, the whole array of items is there, so I know the query is working, and the form element should be built correctly.
But when the select list is display, the sixth element goes missing. I've found a short term way to circumvent this, by adding a dummy sixth item, but that's not going to fly in the long term.
What I need to know is where does it go after form_type_select_value?
edit: More info
This is happening in an Entityform where the field type is Entity Reference and the Widget is Select List. In Manage Fields under Entity Selection, I select an entity called Store, in Simple mode. There are 15 Stores, and these are sorted by the Title property, sorted in the Ascending direction.
When I sort in Descending direction, a different item is missing, but it's always the 6th from the top.
I've debugged it up to the point where the data comes in, before it's rendered, and it's all there in the outgoing array.

Parse Data Model for users tagging items

im trying to figure out a good data model approach when using parse (underlying mongodb) for users that are allowed to select a tag and provide a value to them, lets call it just a rating since thats the easiest to understand.
Im working on a class that is called user tags that has the following structure currently in its collection.
User (pointer to user class)
Object (pointer to object to tag)
Tags (array of tags with values)
The tags can be up to maybe 30 tags and each one of them can have a rating of 1-5 in this case...
I was wondering if I could do a PFRelationship in an array that has the objectId of the tag as the key and value as the 1 - 5 rating.. here is an example json object mocked up to what im saying.
{
"3q24afadfadf": 3.5 //parse relation object id : value,
"234rrdfadfk": 2.4 //parse relation object id : value,
"as4q2w34lsdf": 2.3 //parse relation object id : value
}
This way I can store one row for the item that the user tagged and all the tags with its rating value along with that.
I'm not sure this is the right way or if its scalable when doing queries for get me all users items he or she tagged, along with the tag (name) and the values).
I also on top of that need to figure out a way to when many users tag the same item with different values that I build up some analytics or maybe counter class that gets incremented or averaged in to then be displayed along with the item. I might try cloudcode to do saveafter to update the analytic data class for that item.
Anyhow Any thoughts on this model would be appreciated and most importantly need to be able to get at the data inside the tag array, with hopefully the key being a pointer, if not a pointer i'm up to suggestions because the result should return
Item A
Tag name 1 with value 4.5
Tag Name 2 with value 3.5
and so on..
...
Also if you have any pointers to how to build aggregated data of the item and its over all value that many users have tagged over time.. My thought as above is to have a analytic class that the cloud code increments or that the app then increments, the challenge is to load all the user tags of item x, and get the tag and value out of the array and then add them to the analytic class. I could run this at night since it doesn't have to be real time.

How to work with select input with data coming from a simple relational db model

I'm using Angularjs plugged into a API which retrieves data from a mysqlk normal relational db.
Let's say I have this simple data model in my bdd:
table car:
id,
type_id
table type:
id,
label
I have a API which retrieves the data from DB to have the list of cars and the static labels from db:
http://myapi/car/
response :
{[{id:1, type_id:2}, {id:2, type_id:3}]}
http://myapi/carstaticlabel/
response :
{[{id:1, label:convertible}, {id:2, label:limousine}, {id:3, label:pickup}]}
My aim is first to display a list of cars with the type label and then, open a dialog and being able to show a form with preloaded values of the selected car:
rendered list of cars :
1 convertible
2 pickup
rendered form for edited car whose id is 1:
select the type of car:
<select>
<option value="1">convertible</option>
<option value="2" selected="selected">limousine</option>
<option value="3">pickup</option>
</select>
I have tried different approaches but none is elegant
Solution 1
for the list of cars
change my API and make the join directly between car and type to get the list with label:
http://myapi/car/
response :
{[{id:1, type_id:2, type:{[id:2, label:limousine]}}, {id:2, type_id:3, type:{[id:3, label:pickup]}}]}
then I just assign in the form : car.id and car['type']['label']
ISSUE: each car will contain repeated information (label) >> bloated info
for the edit form:
I pass the json of selected car to the form and set default values:
<p>type: <select ng-model="car.type" ng-options="type.label for type in type_list" required></select></p>
MY ISSUE with that:
when I submit the form, I don't get the type_id directly, I get the car.type object instead, so I need to painfully translate it into an id to post into the database.
To convert I have to go into the car.type object and retrieve the object inside and then retrieve its id... very unelegant.
Solution 2
make the "join" inside angular by working with arrays.
ISSUE: very hard to default values in the form later on
I'm lost, what is usually the best practice to achieve that simple task?
You should use select as label for value in array syntax for array data sources. Your example have complex data structure which is array of objects. So you need something like this:
<select ng-model="selectedId"
ng-options="x.id as x.label for x in response">
</select>
I created little example here to demonstrate proposed solution.

VSTO Selecting and Modifying an existing Ordered List

I have an ordered list in my Word document, and I want to add a new element between elements 2 and 3. The easiest way to do this would probably be to get the location of the end of the second element, but I don't know how to do this. Does anyone know how to do this?
All help is greatly appreciated and I always accept an answer!
Given a document consisting of just a simple ListParagraph:
List item 1
List item 2
List item 3
If you want to insert a list item between 2 and 3, you can get the second list paragraph and add a paragraph:
MSWord.Application app = (MSWord.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
MSWord.Document doc = app.ActiveDocument;
doc.ListParagraphs[2].Range.Paragraphs.Add();
this will insert a new 3rd list paragraph:
List item 1
List item 2
---->code will add this one
List item