From 68c79754cad7afeee998aa94546c3850f533a947 Mon Sep 17 00:00:00 2001 From: Tyler Frankenstein Date: Sun, 8 Sep 2013 16:03:47 -0500 Subject: [PATCH] #178. Changed drupalgap_entity_build_from_form_state() to take into account the language code and delta values of the form state values when assembling the entity. --- modules/entity/entity.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/entity/entity.js b/modules/entity/entity.js index 98f05d91..ed1fd1bd 100644 --- a/modules/entity/entity.js +++ b/modules/entity/entity.js @@ -144,31 +144,22 @@ function drupalgap_entity_render_field(entity_type, entity, field_name, field) { */ function drupalgap_entity_build_from_form_state(form, form_state) { try { - if (drupalgap.settings.debug) { - console.log('drupalgap_entity_build_from_form_state'); - } var entity = {}; - // Use the default language, unless the entity has one specified. - /*var language = drupalgap.settings.language; - if (entity_edit.language) { - language = entity_edit.language; - }*/ + var language = drupalgap.settings.language; $.each(form_state.values, function(name, value){ - var key = drupalgap_field_key(name); + // Attach the key and value to the entity. + var key = drupalgap_field_key(name); // e.g. value, fid, tid, nid, etc. if (key) { - // Attach the key and value to the entity. - eval('entity.' + name + ' = {};'); - eval('entity[name][drupalgap.settings.language] = [{"' + key + '":value}];'); + var delta = 0; + eval('entity.' + name + ' = {' + language + ':[{' + key + ':"' + value[language][delta] + '"}]}'); } else { - entity[name] = value; + entity[name] = value; } }); return entity; } - catch (error) { - alert('drupalgap_entity_build_from_form_state - ' + error); - } + catch (error) { drupalgap_error(error); } } /**