Skip to content

Commit 6ccef35

Browse files
committed
MDL-83862 Add question bank filter validation documentation
1 parent 6e65af5 commit 6ccef35

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/apis/plugintypes/qbank/filters.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,21 @@ constructor which receives the current `$qbank` view object, and extract some da
224224
For example, the
225225
[tag condition](https://github.com/moodle/moodle/blob/main/question/bank/tagquestion/classes/tag_condition.php)
226226
will find the context of the current page, and use that to control which tags are available in the filter.
227+
228+
#### Validation
229+
230+
<Since
231+
version="5.0"
232+
issueNumber="MDL-83862"
233+
/>
234+
235+
Filters support standard [Client-side form validation](https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation).
236+
The simplest way to implement this is to set validation properties on your inputs in the mustache template used by your `addValueSelector()` method.
237+
238+
If you need something more advanced, you can define a `validation()` method in your filter class. This is called when the "Apply filters" button is
239+
clicked, giving you the opportunity to inspect the current values of the filter, and perform validation checks. If validation fails, you should
240+
display errors using the standard `setCustomValidity()` and `reportValidity()` methods on your filter's input elements, and return `false`.
241+
See `core/datafilter/filtertypes/datetime` for an example.
242+
243+
This client-side validation is only to prevent invalid values being entered in the UI. You should also validate data received by the
244+
`build_query_from_filter()` method in your condition class, and throw exceptions in the event of validation failures.

0 commit comments

Comments
 (0)