Appending new selections after pre-populating with Ajax.

88 views
Skip to first unread message

in...@monstermove.uk

unread,
May 28, 2016, 5:42:43 AM5/28/16
to select2
Hi, guys. I hope someone can help me. I have a multiple select field on a profile page which accepts postcodes. My visitors can choose postcodes from an Ajax populated list which I implode and save to the database as a string. When the user returns to their profile page, I pre-populate the field with the saved items like so...

// Split the postcodes
var postcodes = data.postcodeReach.split(',');

for(i=0; i < postcodes.length; i++){
$('.select2-selection__rendered').append('<option class="select2-selection__choice" title="'+postcodes[i]+'"><span class="select2-selection__choice__remove" role="presentation">×</span>'+postcodes[i]+'</option>');
}

My problem is, that if a user tries to add further items to the pre-populated list, it removes all of the existing items instead of appending them.

I have two Ajax instances working on this field. One works on a database table with all of the postcodes in the system and the other pulls data from a row in the
user profile table. I'm wondering if there is a conflict.

I hope someone can help.

Kind regards,

Kevin Brown

unread,
Jun 6, 2016, 5:15:56 PM6/6/16
to select2
The following Stack Overflow question may be of help to you.


--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at https://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

Mark Bell

unread,
Jun 7, 2016, 4:10:05 AM6/7/16
to sel...@googlegroups.com

Thanks, Kevin. I’ll have a look this afternoon.

 

 

Kind regards, Mark

 

Monstermove Removals
https://monstermove.uk
https://facebook.com/monstermove.uk
https://twitter.com/monstermoveuk
0800 999 333 9
07517 342 588

--
You received this message because you are subscribed to a topic in the Google Groups "select2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/select2/tzAob1hK8Z8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to select2+u...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages