<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Moodle 4.x LMS: Show/Hide Profile Sections and Fields	</title>
	<atom:link href="https://www.elearningworld.org/moodle-4-lms-show-hide-profile-sections-and-fields/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.elearningworld.org/moodle-4-lms-show-hide-profile-sections-and-fields/</link>
	<description>For the online learning world</description>
	<lastBuildDate>Tue, 14 Nov 2023 06:17:19 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: CarlosH		</title>
		<link>https://www.elearningworld.org/moodle-4-lms-show-hide-profile-sections-and-fields/#comment-1676</link>

		<dc:creator><![CDATA[CarlosH]]></dc:creator>
		<pubDate>Tue, 14 Nov 2023 06:17:19 +0000</pubDate>
		<guid isPermaLink="false">https://www.elearningworld.org/?p=15818#comment-1676</guid>

					<description><![CDATA[Michael,
Thanks for this article it put me on the right track on how to customize the user profile. However, on the how to expand sections using JavaScript, your proposed solution doesn&#039;t work for me on version 4.0.6 (not tested, but possible also in 4.1 and 4.2). The reason is because the last possible &quot;Additional HTML&quot; option is &quot;Before BODY is closed&quot;. At that point there are two problems; the &quot;collapseElement-x&quot; ids are not available yet (so cannot be referred)  and also the collapse Elements action has not been attached yet (click action will do nothing). The first problem could be solved by using a selector like &quot;document.querySelector(&#039;#id_moodle_optional a&#039;)&quot; instead but the second problem can not solved as there is not click event yet.

Debugging on how this comes to exists later, I see that it is put into a jQuery Deferred Promise by the &quot;EXPAND ALL&quot; &quot;collapsemenu&quot; component when the require &quot;core_form/collapsesections&quot; is called. Unfortunately this promise is not accessible at global level or even at the moment of the &quot;Before BODY&quot; section, this has not been created yet. Oh well, that should had been an easy solution by just adding an extra &quot;.then&quot; callback to the promise.

Back to the drawing board. I didn&#039;t want to put an ugly setTimeout (I know that will work). I wanted to put my own promise or event that will tell me when the collapse Elements are available and ready. I looked into the last things &quot;collapsesections&quot; does. It collects all the collapse Elements ids and put them into the attribute &quot;aria-controls&quot;. So, I see that I could use a MutationObserver that when an attribute is modified, it will trigger a callback and everything is ready. So I ended with code like this:


if (document.getElementById(&#039;page-login-signup&#039;) &#124;&#124; document.getElementById(&#039;page-user-editadvanced&#039;)) {
  const observer = new MutationObserver(() =&#062; {
    document.querySelector(&#039;#collapseElement-4&#039;).click();
    document.querySelector(&#039;#collapseElement-5).click();
    observer.disconnect();
  });
  observer.observe(document.querySelector(&#039;.collapsemenu&#039;), {attributeFilter: [&#039;aria-controls&#039;]});
}


I simplified the full MutationObserver formal callback as I do not need to iterate on the records and I do not need to check which attribute mutated as I filtered to observe only one.

I hope this save hours of frustration to anybody else with the same problem. Maybe you could improve your article, as it is referred on the Moodle documentation.]]></description>
			<content:encoded><![CDATA[<p>Michael,<br />
Thanks for this article it put me on the right track on how to customize the user profile. However, on the how to expand sections using JavaScript, your proposed solution doesn&#8217;t work for me on version 4.0.6 (not tested, but possible also in 4.1 and 4.2). The reason is because the last possible &#8220;Additional HTML&#8221; option is &#8220;Before BODY is closed&#8221;. At that point there are two problems; the &#8220;collapseElement-x&#8221; ids are not available yet (so cannot be referred)  and also the collapse Elements action has not been attached yet (click action will do nothing). The first problem could be solved by using a selector like &#8220;document.querySelector(&#8216;#id_moodle_optional a&#8217;)&#8221; instead but the second problem can not solved as there is not click event yet.</p>
<p>Debugging on how this comes to exists later, I see that it is put into a jQuery Deferred Promise by the &#8220;EXPAND ALL&#8221; &#8220;collapsemenu&#8221; component when the require &#8220;core_form/collapsesections&#8221; is called. Unfortunately this promise is not accessible at global level or even at the moment of the &#8220;Before BODY&#8221; section, this has not been created yet. Oh well, that should had been an easy solution by just adding an extra &#8220;.then&#8221; callback to the promise.</p>
<p>Back to the drawing board. I didn&#8217;t want to put an ugly setTimeout (I know that will work). I wanted to put my own promise or event that will tell me when the collapse Elements are available and ready. I looked into the last things &#8220;collapsesections&#8221; does. It collects all the collapse Elements ids and put them into the attribute &#8220;aria-controls&#8221;. So, I see that I could use a MutationObserver that when an attribute is modified, it will trigger a callback and everything is ready. So I ended with code like this:</p>
<p>if (document.getElementById(&#8216;page-login-signup&#8217;) || document.getElementById(&#8216;page-user-editadvanced&#8217;)) {<br />
  const observer = new MutationObserver(() =&gt; {<br />
    document.querySelector(&#8216;#collapseElement-4&#8217;).click();<br />
    document.querySelector(&#8216;#collapseElement-5).click();<br />
    observer.disconnect();<br />
  });<br />
  observer.observe(document.querySelector(&#8216;.collapsemenu&#8217;), {attributeFilter: [&#8216;aria-controls&#8217;]});<br />
}</p>
<p>I simplified the full MutationObserver formal callback as I do not need to iterate on the records and I do not need to check which attribute mutated as I filtered to observe only one.</p>
<p>I hope this save hours of frustration to anybody else with the same problem. Maybe you could improve your article, as it is referred on the Moodle documentation.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anonymous		</title>
		<link>https://www.elearningworld.org/moodle-4-lms-show-hide-profile-sections-and-fields/#comment-1583</link>

		<dc:creator><![CDATA[Anonymous]]></dc:creator>
		<pubDate>Sun, 22 Jan 2023 12:17:16 +0000</pubDate>
		<guid isPermaLink="false">https://www.elearningworld.org/?p=15818#comment-1583</guid>

					<description><![CDATA[Hi Michael.
Thank you for these fruitful tips.
I need to make visible the default profile field &quot;Mobile Phone&quot; (under the &quot;Optional&quot; section on the user profile page) on the signup page. I don&#039;t want to create a custom profile field to collect the mobile phone numbers since there is already a default field for that. But, I couldn&#039;t find a way to make it visible or at least a required field. If possible, I&#039;ll be able to send a 2-step verification code on login. I don&#039;t want the users to go to the profile page and fill in that field after signup. That&#039;s also not feasible to collect that data because most of the users don&#039;t update their profile if it&#039;s not a required field. Thank you.]]></description>
			<content:encoded><![CDATA[<p>Hi Michael.<br />
Thank you for these fruitful tips.<br />
I need to make visible the default profile field &#8220;Mobile Phone&#8221; (under the &#8220;Optional&#8221; section on the user profile page) on the signup page. I don&#8217;t want to create a custom profile field to collect the mobile phone numbers since there is already a default field for that. But, I couldn&#8217;t find a way to make it visible or at least a required field. If possible, I&#8217;ll be able to send a 2-step verification code on login. I don&#8217;t want the users to go to the profile page and fill in that field after signup. That&#8217;s also not feasible to collect that data because most of the users don&#8217;t update their profile if it&#8217;s not a required field. Thank you.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Stuart		</title>
		<link>https://www.elearningworld.org/moodle-4-lms-show-hide-profile-sections-and-fields/#comment-1581</link>

		<dc:creator><![CDATA[Stuart]]></dc:creator>
		<pubDate>Fri, 20 Jan 2023 02:44:44 +0000</pubDate>
		<guid isPermaLink="false">https://www.elearningworld.org/?p=15818#comment-1581</guid>

					<description><![CDATA[Some amazing tips and examples in there Michael - I learned a few new things - thanks so much for sharing !]]></description>
			<content:encoded><![CDATA[<p>Some amazing tips and examples in there Michael &#8211; I learned a few new things &#8211; thanks so much for sharing !</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
