LMSouq
moodle-core Open

Adding new moodle UI elements according to the onchange event of a select element

GA
gal007
1 month ago
3 views
Problem Description
I'm new in moodle and I always programmed at client-side. I think maybe I'm missing something because of that reason. I need to provide the user with diverse UI elements, according to what he selects in a combo. So I was thinking in writing the lements according to a strategy (design pattern). From an object in the mod_form.php, I was trying to execute something like this: $this -> _form -> addElement('select', 'displayStrategy', get_string('displayStrategy', 'xForum'), $displayStrategy, array('onchange' => 'javascript: function loadStrategy(selVal){ $.ajax({ type: "POST", url: "../mod/xForum/action/displayStrategy.php", data: { class: selVal } }).done(function( msg ) { console.log("Strategy was executed"); }); }; loadStrategy(this.value);') ); That is being executed and the log is printed in the console, but the content in displayStrategy.php is never executed, a "loading" effect is added to the current view and a last problem is I also need to call a function in the same object that is writting the UI ( the one in mod_form.php that executes all the $this -> _form -> addElement(...)) Can you give me a hand? How can I execute those methods according to the strategy? Thanks a lot!

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base