[BEHAVIOR] Datalist for Textbox

Post your completed addons to share with the community

Post » Mon Apr 01, 2013 8:42 pm

Good job on the behaviorization :]
B
20
S
5
G
8
Posts: 325
Reputation: 6,473

Post » Tue Apr 09, 2013 10:56 pm

@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:
[code]
     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 crer 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;
               jQuery(word).appendTo(self.datalist);
          }

          jQuery(document).ready( function() {
                    /** on rcupre la textbox concerne **/
                    var textbox = self.inst.elem;
                    textbox.setAttribute("list", "datalist"+self.inst.uid);
                    /** on ajoute l'lment datalist au projet **/
                    jQuery(self.datalist).appendTo(self.runtime.canvasdiv ? self.runtime.canvasdiv : "body");

               }
          );

     };
[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Apr 10, 2013 7:19 pm

@Yann
Merci t'es un chef.

Version 1.01 (10/04/2013) - Changelog
CHANGE - Improve code (Thanks to Yann).
B
44
S
12
G
13
Posts: 628
Reputation: 10,471

Post » Wed Apr 10, 2013 7:23 pm

@septeven
J't'en prie (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jul 22, 2015 10:33 am

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?
B
14
S
2
Posts: 95
Reputation: 1,086

Previous

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests