MDL-19756 Added a shortcut method to moodle_html_components: add_confirm_action($message). This adds the appropriate onclick event handler for a confirmation message and can be used on any component that gets prepared properly by a renderer function.

This commit is contained in:
nicolasconnault
2009-08-10 07:31:31 +00:00
parent beb56299ec
commit e6fcbe276d
2 changed files with 11 additions and 2 deletions
+1 -2
View File
@@ -2595,8 +2595,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
$form->id = $formid;
if ($jsconfirmmessage) {
$confirmaction = new component_action('click', 'confirm_dialog', array('message' => $jsconfirmmessage));
$form->button->add_action($confirmaction);
$form->button->add_confirm_action($jsconfirmmessage);
}
$output = $OUTPUT->button($form);
+10
View File
@@ -220,6 +220,16 @@ class moodle_html_component {
$this->label->text = $text;
}
}
/**
* Shortcut for adding a JS confirm dialog when the component is clicked.
* The message must be a yes/no question.
* @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
* @return void
*/
public function add_confirm_action($message) {
$this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message)));
}
}
/// Components representing HTML elements