Skip to content

Commit

Permalink
MDL-75969 behat: Allow the editor field to request a save
Browse files Browse the repository at this point in the history
Some editors do not immediately store their content to the textarea they
represent and only do so when the form is submitted or they are
requested to.

This change adds to the existing API to allow an (optional)
`store_current_value` function to be defined for the editor type so that
it can use the JavaScript API to persist any current content to the
editor.
  • Loading branch information
andrewnicols committed Oct 14, 2022
1 parent efc6d19 commit 100fad0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/behat/form_field/behat_form_editor.php
Expand Up @@ -60,6 +60,23 @@ public function set_value($value): void {
}
}

/**
* Returns the current value of the select element.
*
* @return string
*/
public function get_value(): string {
if ($this->running_javascript()) {
// Give any listening editors a chance to persist the value to the textarea.
// Some editors only do this on form submission or similar events.
behat_base::execute_in_matching_contexts('editor', 'store_current_value', [
$this->field->getAttribute('id'),
]);
}

return parent::get_value();
}

/**
* Select all the text in the form field.
*
Expand Down

0 comments on commit 100fad0

Please sign in to comment.