Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.

Commit 39353a2

Browse files
committed
Merge pull request #357 from raihan2006i/setoptions
Implemented setOptions() function
2 parents 2c66817 + ab26a77 commit 39353a2

File tree

2 files changed

+321
-96
lines changed

2 files changed

+321
-96
lines changed

demo.html

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,225 @@ <h2>Local Data Search with custom propertyToSearch, resultsFormatter and tokenFo
456456
</script>
457457
</div>
458458

459+
<h2>Change propertyToSearch anytime</h2>
460+
<div>
461+
<input type="text" id="demo-input-change-propertytosearch-anytime" name="blah" />
462+
Search by :<input type="radio" checked="checked" name="search_key" value="first_name" /> First Name
463+
<input type="radio" name="search_key" value="last_name" /> Last Name
464+
<input type="radio" name="search_key" value="email" /> Email
465+
<input type="radio" name="search_key" value="url" /> Url <br />
466+
<input type="button" value="Submit" />
467+
<script type="text/javascript">
468+
$(document).ready(function() {
469+
$('input[name="search_key"]').click(function() {
470+
$("#demo-input-change-propertytosearch-anytime").tokenInput("setOptions", {propertyToSearch: $(this).val(), hintText: "Type "+$(this).val()+" here to search"});
471+
});
459472

473+
$("#demo-input-change-propertytosearch-anytime").tokenInput([{
474+
"id": 1,
475+
"first_name": "Arthur",
476+
"last_name": "Godfrey",
477+
"email": "[email protected]",
478+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
479+
},
480+
{
481+
"id": 2,
482+
"first_name": "Adam",
483+
"last_name": "Johnson",
484+
"email": "[email protected]",
485+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
486+
},
487+
{
488+
"id": 3,
489+
"first_name": "Jeff",
490+
"last_name": "Johnson",
491+
"email": "[email protected]",
492+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
493+
},
494+
{
495+
"id": 4,
496+
"first_name": "Adriana",
497+
"last_name": "Jameson",
498+
"email": "[email protected]",
499+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
500+
},
501+
{
502+
"id": 5,
503+
"first_name": "Adriano",
504+
"last_name": "Pooley",
505+
"email": "[email protected]",
506+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
507+
},
508+
{
509+
"id": 6,
510+
"first_name": "Alcir",
511+
"last_name": "Reis",
512+
"email": "[email protected]",
513+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
514+
},
515+
{
516+
"id": 7,
517+
"first_name": "Jack",
518+
"last_name": "Cunningham",
519+
"email": "[email protected]",
520+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
521+
},
522+
{
523+
"id": 8,
524+
"first_name": "Alejandro",
525+
"last_name": "Forbes",
526+
"email": "[email protected]",
527+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
528+
},
529+
{
530+
"id": 9,
531+
"first_name": "Alessandra",
532+
"last_name": "Mineiro",
533+
"email": "[email protected]",
534+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
535+
},
536+
{
537+
"id": 10,
538+
"first_name": "Alex",
539+
"last_name": "Frazo",
540+
"email": "[email protected]",
541+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
542+
},
543+
{
544+
"id": 11,
545+
"first_name": "Alexandre",
546+
"last_name": "Crawford",
547+
"email": "[email protected]",
548+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
549+
},
550+
{
551+
"id": 12,
552+
"first_name": "Alexandre",
553+
"last_name": "Lalwani",
554+
"email": "[email protected]",
555+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
556+
},
557+
{
558+
"id": 13,
559+
"first_name": "Alexandre",
560+
"last_name": "Jokos",
561+
"email": "[email protected]",
562+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
563+
},
564+
{
565+
"id": 14,
566+
"first_name": "Alexandre",
567+
"last_name": "Paro",
568+
"email": "[email protected]",
569+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
570+
},
571+
{
572+
"id": 15,
573+
"first_name": "Andre",
574+
"last_name": "Niemeyer",
575+
"email": "[email protected]",
576+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
577+
},
578+
{
579+
"id": 16,
580+
"first_name": "Alyssa",
581+
"last_name": "Fortes",
582+
"email": "[email protected]",
583+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
584+
},
585+
{
586+
"id": 17,
587+
"first_name": "Amit",
588+
"last_name": "Alvarenga",
589+
"email": "[email protected]",
590+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
591+
},
592+
{
593+
"id": 18,
594+
"first_name": "Ana Bia",
595+
"last_name": "Borges",
596+
"email": "[email protected]",
597+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
598+
},
599+
{
600+
"id": 19,
601+
"first_name": "Ana",
602+
"last_name": "Akamine",
603+
"email": "[email protected]",
604+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
605+
},
606+
{
607+
"id": 20,
608+
"first_name": "Anderson",
609+
"last_name": "Tovoros",
610+
"email": "[email protected]",
611+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
612+
},
613+
{
614+
"id": 21,
615+
"first_name": "Andre",
616+
"last_name": "Borges",
617+
"email": "[email protected]",
618+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
619+
},
620+
{
621+
"id": 22,
622+
"first_name": "Andre",
623+
"last_name": "Wexler",
624+
"email": "[email protected]",
625+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
626+
},
627+
{
628+
"id": 23,
629+
"first_name": "Andre",
630+
"last_name": "Williams",
631+
"email": "[email protected]",
632+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
633+
},
634+
{
635+
"id": 24,
636+
"first_name": "Andre",
637+
"last_name": "Sanford",
638+
"email": "[email protected]",
639+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
640+
},
641+
{
642+
"id": 25,
643+
"first_name": "Andre",
644+
"last_name": "Wayne",
645+
"email": "[email protected]",
646+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
647+
},
648+
{
649+
"id": 26,
650+
"first_name": "Andre",
651+
"last_name": "Jackson",
652+
"email": "[email protected]",
653+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
654+
},
655+
{
656+
"id": 27,
657+
"first_name": "Andre",
658+
"last_name": "Jolly",
659+
"email": "[email protected]",
660+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
661+
},
662+
{
663+
"id": 28,
664+
"first_name": "Andre",
665+
"last_name": "Henderson",
666+
"email": "[email protected]",
667+
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
668+
}
669+
], {
670+
propertyToSearch: "first_name",
671+
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='first_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div><div class='url'>" + item.url + "</div></div></li>" },
672+
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " " + item.last_name + "</p></li>" },
673+
});
674+
});
675+
</script>
676+
</div>
677+
460678
<h2>Start disabled</h2>
461679
<div>
462680
<input type="text" id="demo-input-disabled" name="blah" />

0 commit comments

Comments
 (0)