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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user