Page MenuHomePhabricator

Stop using onclick attributes and globally scoped functions
Open, LowPublic


This be yuck✓&q=onclick

onclick html attributes depend on globally scoped javascript functions, which we try to avoid using. Instead, we should be using JS resource loader modules, that find the right elements from the page ready and attach eventlisteners to those elements

protected function getButton( $msg, $source, $target ) {
		$html = Xml::element( 'input', [
			'type' => 'button',
			'value' => wfMessage( $msg )->text(),
			'onclick' => Xml::encodeJsCall( 'appendFromSelect', [ $source, $target ] )
		] );

		return $html;
window.appendFromSelect = function ( selectid, targetid ) {

rewrite, so that the JS setup is no longer in the HTML, but instead in something like $( document ).ready, which finds the thml button and then attaches a click handler calling appendFromSelect (an removing appendFromSelect from the window object).

Event Timeline

TheDJ created this task.Feb 25 2016, 10:31 PM
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptFeb 25 2016, 10:31 PM
Danny_B moved this task from Unsorted to Needs removal on the Technical-Debt board.
Nikerabbit triaged this task as Low priority.Apr 13 2016, 6:58 AM
Nikerabbit added a subscriber: Nikerabbit.

Most of these are in the deprecated TUX ui.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptApr 20 2016, 11:58 AM

Hello, The bug represents to remove the onclick attributes?

@Dheerajmalisetty: The task summary says "Stop using onclick attributes". Hence I am not sure what exactly is unclear and made you ask. :)

@Aklapper : Do I need to comment the onclick attribute.

@Dheerajmalisetty: Why don't you just try it, make your changes locally, test if your changes fix this task, and then propose a patch in Gerrit?
Please see the first bullet point here:,_questions_and_support

TheDJ updated the task description. (Show Details)Jan 21 2018, 4:29 PM
TheDJ added a comment.Jan 21 2018, 5:18 PM

@Dheerajmalisetty i slightly expanded the description of the ticket to further clarify what needs to be done.

Swayamsrk added a subscriber: Swayamsrk.

Let me try.

TheDJ updated the task description. (Show Details)Mon, Feb 10, 9:10 PM

i gave you some more details to work with :D