[BEHAVIOR] Datalist for Textbox

0 favourites
  • 14 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Datalist

    for Textbox

    Version: 1.01 (10/04/2013)

    Download Datalist.rar

    For eski

    (his request)

    Provide an auto-completion option to the C2 natives textboxes.

    How to - This is a behavior from a former plugin I did. Just add this behavior to a textbox, and set the words list you need to use with auto-completion (in the behavior properties or by actions).

    Because I transformed the plugin into a behavior, let me know if you need the archive file of the original plugin. Also, let me know if you find any bugs, or need sth else.

    Thanks

  • Hey that's great!

    Maybe it would be slightly more straightforward with as a "datalist textbox" object directly, with the additional parameter?

    In my case, I have a list of about 200 000 items, so I would need a way to make ajax requests I guess, but the plugin is neat already for small lists

    (If you're interested, it's an ini file over here, to which I'm making php requests like this for the moment - it's not really important that I add the feature, I suppose it would need advanced server side scripting too)

  • lemo

    Yes but ashley asked to developers to not make plugins addons of official plugins.

    About Ajax, I guess you can use it with this plugin.

  • septeven Ah, I see

    Maybe it would make sense as a behavior then? (people would just apply it instead of that manual linking)

    For example like the behavior by rexrainbow for text scrolling(I haven't tried it tho)

  • lemo

    Yes iI thought about this but I never made any behavior - I should take a look.

  • septeven

    Using "this.inst" to get the reference of main object in behavior.

    Then use this reference at "apply"(or "call") with action.

    For example,

    github.com/rexrainbow/C2_plugins/blob/master/behaviors/rex_text_typing/runtime.js

    cr.plugins_.Text.prototype.acts.SetText.apply(this.inst, [param]);
  • Thanks rexrainbow

    I transformed the plugin into a behavior.

    rexrainbow, do you know how to wait for the complete loading of this.inst.elem though ?

  • Sorry, I don't know. I guess there might be a callback for this event.

    Pode might know the answer.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • OK thanks, maybe Ashley will know as well ?

  • Good job on the behaviorization :]

  • septeven

    I think you can create the datalist node outside of the jQuery(document).ready() call

    That's just when you append it to the canvasdiv node that you have to be sure it's been loaded.

    You also just need to wait to set the Attribute of the element.

    In short your behinstProto.onCreate can look like that:

         behinstProto.onCreate = function()
         {
              /** Load properties **/
              this.myProperty = this.properties[0];
    
              var self = this;
              this.wordsArray = [];
    
              this.datalist = document.createElement("datalist");
              this.datalist.id = "datalist" + this.inst.uid;
    
              /** on cr�er une array contenant la liste des mots **/
              self.wordsArray  = self.properties[0].split(",");
              var wordsArrayLength = self.wordsArray.length;
    
              for (var i = 0; i < wordsArrayLength; i++)
              {
                   var word = document.createElement("option");
                   word.value = self.wordsArray[i];
                   jQuery(word).appendTo(self.datalist);
              }
    
              jQuery(document).ready( function() {
                        /** on r�cup�re la textbox concern�e **/
                        var textbox = self.inst.elem;
                        textbox.setAttribute("list", "datalist"+self.inst.uid);
                        /** on ajoute l'�l�ment datalist au projet **/
                        jQuery(self.datalist).appendTo(self.runtime.canvasdiv ? self.runtime.canvasdiv : "body");
    
                   }
              );
    
         };
    
  • Yann

    Merci t'es un chef.

    Version 1.01 (10/04/2013) - Changelog

    CHANGE - Improve code (Thanks to Yann).

  • septeven

    J't'en prie (:

  • Hello,

    i just fund this topic wich is something i really need at the moment.

    just tested this behavior but i get this javascript error:

    cannot read property 'set attribute of undefined

    http://localhost/datalist_behavior.js, line 79 (col11)

    is it possible to get an update?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)