Hi i have created a number of dropdown’s and text boxes for personal information. On the page code the fields have been assigned to either null or undefined depending upon user flow / choice
My current js has me by the balls at the moment. Any changes i make means that i cannot open a collection as this shows internet error which isn’t true. I have saved from a previous version and experimented to prove this.
I think this is because i have saved a previous version that now isn’t fit for purpose.
What i’m trying to achieve is based on the following but has these field keys
nickName, prefix, subPrefix, addOwnPrefix, firstName, middleName, lastName, suffix, addYourownSuffix
on the page code for any fields that will be empty i have assigned null or undefined,
so this is what i have, do i need to create a new js file to stop the collection being corrupted.
I took this code from a forum post and am unsure if the items should also concertina, a correct code example would be great
I’m not sure what exactly you’re trying to do (didn’t have time to go analyze the code), but if all you want is to sequence all the defined fields with a single space between each of them, then you can do something like:
export function Member_afterQuery(item, context) {
let data = [item.nickName, item.subPrefix, item.firstName, item.middleName , item.lastName, item.suffix];
data = data.filter(e => e !== undefined);
data = data.map(e => e.trim());
item.fullName= data.join(' ');
return item;
}
@jonatandor35 ok thanks, i’ll have to give it a go tomorrow. This is such different code from what i had added previously and although not quite right i thought i was on the right track.
ultimately J.D. i thought that any fields that were null or undefined would be trimmed if i constructed the code above properly
Regards
Adam
@adcatch02 you know that the method trim() means ‘Remove white space from the beginning and the end of a string’ right? So undefined cannot be trimmed (I used trim() in the code above because I thought you were trying to remove white spaces).
ok so i’m still at a loose end with this. Just want to put a fullName string together from a js file and leave out any fields that do not have a value
so as background example i have two cascading dropdown’s in page code and if user reaches the second dropdown i have assigned the first one to have a value of null
this also applies to other fields based on above logic. well i hope its logical