an issue with preFill

Moiz's Avatar

Moiz

20 Apr, 2010 08:50 AM

Hi, i seem to have a problem with the preFill option

The JS initialize is as follows :

$("#BLG_tags").autoSuggest("MY_URL", {selectedItemProp: "name", searchObjProps: "name", asHtmlID:'01', preFill:'1,2,' });

notice the preFill has 1 and 2 which is in the json file. attached is a sample json file output

however the error is on this particular line -

org_li.before(item.html(data[opts.selectedItemProp]).prepend(close));

if i alert the value of data[opts.selectedItemProp] it returns undefined! Could someone help me out on this.

  1. 1 Posted by roland on 11 May, 2010 11:04 AM

    roland's Avatar

    Same here, using this code:

    `$(".autosuggest").autoSuggest("<?php echo url_for('mymodule/author'); ?>",

                                  {selectedItemProp: "name", 
                                   searchObjProps: "name", 
                                   startText: "", 
                                   keyDelay: 50, 
                                   minChars: 1,
                                   preFill: '[{"value":"5","name":"Leo"}]'});'
    

    The above code work 100% without the preFill option.
    This is the error I get:
    item.html(data[opts.selectedItemProp]).prepend is not a function on line 340 of the unpacked plugin.

  2. 2 Posted by MikeEng on 23 Jun, 2010 02:18 PM

    MikeEng's Avatar

    I'm having a similar issue. I am using the default dummy data, and I set the PreFill option as:

    startText: "Enter Trait",
    emptyText: "No Results Found",
    preFill: {value: "21", name: "Mick Jagger"}
    limitText: "No More Traits Allowed",
    selectedItemProp: "value", //name of object property
    selectedValuesProp: "value", //name of object property
    

    It is not prefilling the item. I'm not sure if I've set the preFill value in the correct format. Does someone have an example of how to correctly format the definition for the preFill variable?

  3. 3 Posted by MikeEng on 23 Jun, 2010 04:53 PM

    MikeEng's Avatar

    Whew, I found a solution which works, at least with hardcoded data.

    Based on something Lloyd on the comments section on the plugin page suggested,

    I created a new JSON array to define the selected items in the beginning of the file.

    (function($){
    $.fn.autoSuggest = function(data, options) {
        //define selected items here
        var selectedData = {items: [
            {value: "55", name: "Rudy Hamilton"}, 
            {value: "79", name: "Michael Jordan"}]};
    

    Then I defined the preFill option as follows

    var defaults = { 
            asHtmlID: false,
            startText: "Enter Trait",
            emptyText: "No Results Found",
            preFill: selectedData.items,
    
  4. 4 Posted by Muhammad Subair on 05 Jan, 2011 07:25 PM

    Muhammad Subair's Avatar

    Dear All,

    I follow the steps and give the value [{value: "100", name: "Uncategorized"}], for preFill either directly or through a variable.

    But after checking it always give the unwanted hidden value, ie value = 0 beside the real value (default or/and user input).

    Does anyone know the solution?

  5. 5 Posted by jayedgar on 08 Mar, 2011 01:31 PM

    jayedgar's Avatar

    OK, I figured it out, although there's still a small bug. Here's the way to format it:

    [other options...], preFill: [{value: "4", name: "apples"},{value: "3", name: "bananas"}],
    [more options...]

    I notice that there's an extra leading comma when preFill is used. Next I'll see if I can figure out how to remove that. ;o)

  6. 6 Posted by jayedgar on 08 Mar, 2011 01:40 PM

    jayedgar's Avatar

    Found it. Somewhere around line 114 (I've been patching...), REM out the line shown below:

    [...] if(lastChar != ","){ prefill_value = prefill_value+","; }

    //values_input.val(","+prefill_value); //removed, fixes extra comma
    $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
    

    [...]

  7. 7 Posted by Jez Brooks on 17 Apr, 2011 07:06 PM

    Jez Brooks's Avatar

    Unfortunately jayedgar your solution to fix the additional comma creates another error. When loading the first item into the list (either via the preFill or using the autoSuggest drop down) it will not remove that item from the hidden list, even though the selector disappears.

    It seems that without additional work to the js file you need to keep the additional comma if you wish to continue to provide full functionality of removal of the first list item.

  8. 8 Posted by Roland Jungwirt... on 17 Apr, 2011 08:09 PM

    Roland Jungwirth's Avatar

    No content.

  9. 9 Posted by jSuggest on 17 Apr, 2011 08:49 PM

    jSuggest's Avatar

    Check my custom adaptation.

    It has the preFill working.

    It is still in beta, but I think it fits you needs.

    Here is the code.
    http://jsbin.com/asahe5/10/edit

    And here is the demo.
    http://jsbin.com/asahe5/10/edit#preview

  10. 10 Posted by Jez Brooks on 18 Apr, 2011 09:15 AM

    Jez Brooks's Avatar

    jSuggest, when adding new items to your version (using tab/comma), it adds the value as 'null' into the hidden element, thus you'll need to fix this error.

    Also, can you elaborate on what else are your significant changes to the code to require a re-brand and placed back into beta? I'm sorry, but I don't see the advantage of your version over the original with the changes already highlighted in this discussion.

  11. 11 Posted by jSuggest on 20 Apr, 2011 07:11 PM

    jSuggest's Avatar

    @Jez

    Hi, when you need to add a new item, you have to call the newItem function.

    This function sends to you the text input, and you can format it to match your needs.

    For example.

        queryLimit: 3,
        newItem: function (item){ var newItemData = {value: null, name: item}; return newItemData;},
        selectionLimit: 2,
    

    Hope it helps.

  12. 12 Posted by Adam HubShout on 28 Apr, 2011 06:56 PM

    Adam HubShout's Avatar

    Just want to say "great going guys!" I hit this little preFill bug also and this thread helped me solve it!

    Combined with server-side scripting, you can really make this thing groovy! Excellent work dudes! Keep it up.

  13. 13 Posted by AdamElevate on 11 May, 2011 08:27 PM

    AdamElevate's Avatar

    This thread totally saved me! Thanks guys

  14. 14 Posted by LuiGui on 31 Jan, 2012 02:38 PM

    LuiGui's Avatar

    Hey, hello to all, i'm from peru, and my solution work to 100%.

    Next this lines:

                    if (typeof opts.preFill == "string") {
                    var vals = opts.preFill.split(",");
                    for (var i = 0; i < vals.length; i++) {
                        var v_data = {};
    

    Copy and paste, this lines:

                        //agrega el item completo de la matriz de datos
                        if ((typeof data != "undefined") || (typeof data != "null")) {
                            for (var g = 0; g < data.length; g++) {
                                if (data[g].value == vals[i]) {
                                    v_data[opts.selectedValuesProp] = data[g].value;
                                    v_data[opts.selectedItemProp] = data[g].name;
                                }
                            }
                        }
                        //fin de la función
    

    Sorry for my english.
    Hope it helps.

  15. 15 Posted by Prasad on 13 Aug, 2012 03:53 PM

    Prasad's Avatar

    @MikeEng

    Hey u saved my ass.
    I wasted my lots of time on this.

  16. 16 Posted by andrei on 15 Aug, 2012 08:01 PM

    andrei's Avatar

    @jayedgar thanks, your response with array over dict worked by adding different value/name for autosuggest. Saved my day from going into digging code :)

  17. 17 Posted by David Rosendo on 17 Jan, 2013 11:41 PM

    David Rosendo's Avatar

    Actually to make this work...

    Im accpeting a string, ex; bla bla, bli bli

    just added

    v_data[opts.selectedItemProp] = vals[i];

    after

    v_data[opts.selectedValuesProp] = vals[i];

  18. 18 Posted by happy wheels t ... on 17 May, 2014 08:05 AM

    happy wheels t shirt
's Avatar

    happy wheels free Game titles On the internet can be an on the internet rushing sport. With creative and also excellent design, combined with its entertaining, thrilling, race as well as scoring method of which maintains you entertained for hours. Included in this kind of online game is usually a totally crammed amount publisher which enables you to let loose ones creativeness as well as develop by far the most weird in addition to odd amounts you can imagine. Happy Trolley wheels Tryout degrees can be played as well as liked from your friends also. For you to specifically leap in to the race venture, pick perform and choose any kind of levels along with persona and revel in. It is a strictly reasonable physics primarily based second podium structured area scrolling video game that has bizarre and difficult degrees that can test out that you the actual restrict. Ethnic background because the globe will get more difficult, stability, handle and move around ones figures to produce it for the end line without trouble. Actuality physics will certainly toss your current personality hurling tumbling and test out the way very good you happen to be with surviving. The largest challenge would be to steer clear of permitting your current arms and legs separated from a body right mil chunks. Observing like very funny failures in addition to nasty incidents filled with gore along with computer animated death helps make this particular video game much more fun. - View additional with

  19. 19 Posted by Moiz Sitabkhan on 17 May, 2014 08:38 AM

    Moiz Sitabkhan's Avatar

    On Saturday, May 17, 2014, happy wheels t shirt <
    [email blocked]> wrote:

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • generate_tags.json 94 Bytes

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

08 Feb, 2017 08:05 AM
08 Feb, 2017 08:02 AM
08 Feb, 2017 07:56 AM
08 Feb, 2017 07:53 AM
08 Feb, 2017 07:45 AM