Load adm module after form complete

Load adm module after form complete

door Helson C -
Aantal antwoorden: 2

Hello everyone,

I'm trying to create a handle to autocomplete element in a form https://docs.moodle.org/dev/lib/formslib.php_Form_Definition#autocomplete


class my_form extends moodleform{

function definition(){

       $mform = $this->_form;

       $user = array(...);

       $mform->addElement('autocomplete', 'hide_body_id', get_string('searcharea', 'search'), $user, $options);

}

}

-------------------------------

my.php

include_once 'my_form.php';

...

$mform = new admin_form();

$mform->display();

$PAGE->requires->js_call_amd('block_myblock/hide', 'init');

------------------------------------

my_block/amd/src/hide.js

define(['jquery'], function($) {

var t = {

init : function() {

      $('#fitem_id_hide_body_id input[id^=form_autocomplete_input]').on('input', function(){

           $(body).hide();  <----- Never execute

      )};

      )};


return t;
}


I has been noted that "autocomplete" element load in same time that amd module load...

Then I need a way to wait to autcomplete load, then amd module can detect it.


Thanks in advance.

Gemiddelde van de beoordelingen:  -
Als antwoord op Helson C

Correct javascript

door Helson C -

I have typed the code incorrect in the post above...


define(['jquery'], function($) {

var t = {

    init : function() {

      $('#fitem_id_hide_body_id input[id^=form_autocomplete_input]').on('input', function(){

            $('body').hide();

      });

     }

}

return  t;

});



Anyone can help me?


Gemiddelde van de beoordelingen:  -
Als antwoord op Helson C

Re: Correct javascript

door Sam Chaffee -
Foto van Core developers

Hi Helson,

Are there any errors when you build the Javascript with Grunt? If not, could you try making the init function something really simple like console.log('My init functions works!'); just to verify that your AMD module is being included on the page where you expect it? If that works you could try moving the console.log() to inside the .on handler to make sure the handler has been registered correctly.

Gemiddelde van de beoordelingen:  -