json field empty, javascript not validating as null, "", empty
"field_main_profile_age":[]
this is how the json is. On the custom user profile page I wrote, the user entities when this field shows empty doesn't return anything and kind of crashes the page/script.
I am validating using these functions: validation functions
function jd_profile_page_isEmpty(str) {
return (!str || 0 === str.length);
}
function jd_profile_page_empty(e) {
switch (e) {
case "":
case 0:
case "0":
case null:
case false:
case typeof this == "undefined":
return true;
default:
return false;
}
}
function jd_profile_page_strcmp ( str1, str2 ) {
// http://kevin.vanzonneveld.net
// + original by: Waldo Malqui Silva
// + input by: Steve Hilder
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: gorthaur
// * example 1: strcmp( 'waldo', 'owald' );
// * returns 1: 1
// * example 2: strcmp( 'owald', 'waldo' );
// * returns 2: -1
return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
}
function jd_profile_page_determine_defined(val) {
if ( ( typeof val == 'undefined' ) || (jd_profile_page_isEmpty(val)) || (jd_profile_page_empty(val)) ) {
return 'FALSE';
} if ((val) || (!!val) ) { return 'TRUE';} else { return 'FALSE';}
}
here is where the field comes in
if ( (jd_profile_page_strcmp(jd_profile_page_determine_defined(user.field_main_profile_age['']), 'FALSE' ) == 0) ) { }
this if /then is crashing or showing no output or not firing, because I don't think that I have the field label correct. I tried this standard as well, to no avail... user.field_main_profile_age['und'][0]['value']
so how does the field look when the json is like above, on the very first line of this message?
Thnks
Sorry, I don't understand the question here. I don't really see any DrupalGap specific code either, so I'm not sure who/what/where/why/when you're trying to use DrupalGap, jDrupal and JSON from Drupal.
FYI, jDrupal has an empty() function that you should be able to call to check to see if something is empty.