1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding Autocomplete class via JS

Discussion in 'XenForo Development Discussions' started by ragtek, Nov 11, 2011.

  1. ragtek

    ragtek Guest

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

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

    if i do the same in the frontend via
     $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... :(

    what's wrong here?:D
  2. Robbo

    Robbo Well-Known Member

    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.

Share This Page