Adding Autocomplete class via JS

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
I'm having in the acp options some namefields, where i add via js the AutoComplete AcSingle class.

Code:
//devtools: add.jsheader
 
!function($, window, document, _undefined) {
    XenForo.NUNS = function($form) {
        this.__construct($form);
    };
    XenForo.NUNS.prototype =
    {
        __construct: function($form) {
            this.$conversationCheckBox = $('#ctrl_optionsragtek_NUNS_welcomeConversationActive_1');
            this.Init();
        },
 
 
 
        addAutoComplete:function($element, Single) {
            $classes = 'AutoComplete';
            $classes2 = 'AutoComplete AcSingle'; // todo
 
            if (Single) {
                $cl = $classes2;
            }
            else {
                $cl = $classes;
            }
            $element.addClass($cl);
 
        },
...
Init: function() {
            $conversationcb = this.$conversationCheckBox;
            this.addAutoComplete($('#ctrl_optionsragtek_NUNS_welcomeConversationSender'), true);
....
with this the autocomplete is working nice
ac1.webp

if i do the same in the frontend via
Code:
 $input = $('<input type="text" name="watched_username"  autocomplete="off"/>');
                $input.addClass('textCtrl AutoComplete AcSingle');
                $input.xfInsert('appendTo',                    $title.parent().parent().after());
it creates the inputfield, BUT it doesn't attach the Autocomplete Event... :(
ac2.webp

what's wrong here?:D
 
Is there any reason you are creating the element with jQuery? Just from looking at this you should be doing <input type="text" name="watched_username" autocomplete="off" class="AutoComplete" /> and registering .AutoComplete with the XenForo.Register method.

Edit: I think I misunderstood at first. Are you already using XenForo.Register in the JS block above? If so I will explain why this happened and how I got around it.
 
Top Bottom